I have the following:
1. A model called Student, which is an STI sub-class of Person 2. Student has the following associations has_many :homerooms has_many :classrooms, :through => :homerooms
has_one :current_classroom, :through => :homerooms, :source => :classroom, :conditions => "classrooms.year = '" + $current_school_year + "'" 3. in the view, i have student.name + "(" + student.current_classroom.grade + ")"
I need to list all of the students, along with their classroom names (and teacher, but need to get over this hurdle first), so had the following Find in my index action of student_controller
@students = Student.find(:all, :order => 'last_name, first_name', :include => :current_classroom)
But in reviewing the log, I see that people, homerooms, and classroom are all derived from separate queries.
Student Load (0.000000) SELECT * FROM `people` WHERE ( (`people`.`type` = 'Student' ) ) ORDER BY last_name, first_name Homeroom Load (0.002000) SELECT `homerooms`.* FROM `homerooms` WHERE (`homerooms`.student_id = 5122) Homeroom Columns (0.003000) SHOW FIELDS FROM `homerooms` Classroom Columns (0.003000) SHOW FIELDS FROM `classrooms` Classroom Load (0.000000) SELECT * FROM `classrooms` WHERE (`classrooms`.`id` = 16)
I have also tried the following
@students = Student.find(:all, :order => 'last_name, first_name', :include => {:homerooms => :classroom) to no avail.
In either case, the page displays fine, with students and classrooms.
Any idea why Rails seems to be ignoring the :include?
Any help would be greatly appreciated.
Best, Tom