【发布时间】:2017-08-25 22:32:38
【问题描述】:
我有以下场景:
学生属于_to并且有很多课程,
课程有_许多课程
课程属于_课程
这是我目前的模型:
class Student < ActiveRecord::Base
has_many :studentcourses
has_many :courses, :through => :studentcourses
end
class StudentCourse < ActiveRecord::Base //join table
belongs_to :course
belongs_to :student
end
class Course < ActiveRecord::Base
has_many :studentcourses
has_many :students, :through => :studentcourses
has_many :lessons
end
class Lesson < ActiveRecord::Base
belongs_to :course
end
因此,学生被分配到一门或多门课程,并且课程有许多课程。 我如何对其建模,以便我可以检索一个学生的所有课程以及属于该课程的所有学生的所有课程?
【问题讨论】:
标签: ruby-on-rails