2

このようなことはできますか?

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

Enrollment テーブルには、学生が登録されているコース セクションの student_id と section_id だけがあります。

4

0 に答える 0