rails association - 我可以使用:多次?

时间:2012-01-07 18:34:28

标签: rails-models

我可以这样做吗?

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

注册表只有一个student_id和一个学生注册的课程部分的section_id。

0 个答案:

没有答案