Suppose I have three models: Student
, SchoolClass
, and DayOfWeek
. There is a HABTM relationship between Student
and SchoolClass
, and between SchoolClass
and DayOfWeek
. What I'd like to do is find all school classes belonging to a given student that meet on Monday.
Now I suppose I could do something like:
@student = Student.find(:student_id)
@student_classes = @student.school_classes.find(:all)
@student_classes_on_monday = Array.new
@student_classes.each do |student_class|
if student_class.day_of_week.include?("Monday")
@student_classes_on_monday << student_class
end
end
Is there a way to accomplish lines 2-8 in a single find method?