Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
SRCT
schedules
Commits
da99de12
Commit
da99de12
authored
Sep 26, 2018
by
Zach Perkins
Browse files
Enabled instructor search through some spicy joins
parent
9a7970a0
Changes
3
Hide whitespace changes
Inline
Side-by-side
schedules/app/models/course.rb
View file @
da99de12
...
...
@@ -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
...
...
schedules/app/models/course_section.rb
View file @
da99de12
...
...
@@ -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
)
...
...
schedules/app/models/instructor.rb
View file @
da99de12
class
Instructor
<
ApplicationRecord
has_many
:course_sections
def
self
.
name
d
(
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
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment