Commit da99de12 authored by Zach Perkins's avatar Zach Perkins
Browse files

Enabled instructor search through some spicy joins

parent 9a7970a0
......@@ -52,6 +52,8 @@ class Course < ApplicationRecord
query = from_course_number(query, value)
when "title"
query = from_title(query, value)
when "instructor"
query = Instructor.from_name(query.joins("INNER JOIN instructors ON course_sections.instructor_id = instructors.id"), value)
end
end
......
......@@ -57,7 +57,7 @@ class CourseSection < ApplicationRecord
/\d+/.match(query) { |a|
m = a.to_s
if m.length == query.length # Does the number take up the entire query
if m.length == 5 # Check if it is a CRN
if m.length == 5 and from_crn(select("*"), m).count != 0 # Check if it is a CRN
filters["crn"] = m
else # Just assume course_id
filters["course_id"] = Integer(m)
......
class Instructor < ApplicationRecord
has_many :course_sections
def self.named(base_query, name)
base_query.where("name LIKE ?", "%#{name}%")
def self.from_name(base_query, name)
base_query.where("instructors.name LIKE ?", "%#{name}%")
end
end
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment