学校には多くのコースがあります。コースには多くのセクションがあります。学生がコースのセクションに登録します。学校の生徒全員を見つけられるようにしたいです。
Class School < ActiveRecord::Base
has_many :courses
has_many :sections, :through => courses
has_many :students, :through => courses, :through => sections, :through => enrollments
end
Class Course < ActiveRecord::Base
belongs_to :school
has_many :sections
has_many :students, :through => sections, :through => enrollment
end
Class Section < ActiveRecord::Base
belongs_to :course
has_many :students, :through => enrollment
end
Class Student < ActiveRecord::Base
has_many :sections, :through => enrollment
has_many :courses, :through => sections, :through => enrollment
has_many :schools, :through => courses, :through => sections, :through => enrollment
end
登録は、学生がコースのそのセクションに登録するときのセクション ID と学生 ID を含む単なるテーブルです。
私がここでやろうとしていることを行うためのより良い方法はありますか?
ありがとう。