一所学校有很多课程。一门课程有很多部分。学生注册课程的一部分。我希望能够找到学校里所有的学生。
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 的表格。
有没有更好的方法来做我想做的事情?
谢谢。