2

Can I do something like this?

Class School < ActiveRecord::Base
  has_many :courses
  has_many :students, :through => courses, :through => coursesections, :through => enrollments
end

Class Course < ActiveRecord::Base
  has_many :coursesections
  has_one :school
end

Class CourseSection < ActiveRecord::Base
  has_one :course
  has_one :school, :through => courses
  has_many :students, :through => enrollments
end

Class Student < ActiveRecord::Base
  has_many :sections, :through => enrollments
end

The Enrollment table just has a student_id and a section_id for course section that a student is enrolled in.

Deonomo
  • 1,583
  • 3
  • 16
  • 25

0 Answers0