0
assignment (id, name, date)
activity (id, name, desc)
student (id, name, email)

一个作业可以有很多活动,一个作业可以分配给许多学生。需要跟踪学生的每项活动的状态。

所以有一个三主键表:

assignments_activities_students (assignment_id, activity_id, student_id, status)

在下面设置关联,但它不起作用。有人知道怎么做吗?

assignment
  has_many :assignments_activities_students
  has_many :students, :through => :assignments_activities_students
  has_many :activities, :through => :assignments_activities_students

activity
  has_many :assignments_activities_students
  has_many :assignments, :through => :assignments_activities_students
  has_many :students, :through => :assignments_activities_students

student
  has_many :assignments_activities_students
  has_many :assignments, :through => :assignments_activities_students
  has_many :activities, :through => :assignments_activities_students

assignments_activities_students 
  belongs_to :assignment
  belongs_to :activity
  belongs_to :student
4

1 回答 1

1

你有一个Student模型,但你正在添加关系

has_many :users, :through => :assignments_activities_students

Assignment您应该在您的和Activity模型中将其更改为以下内容。

has_many :students, :through => :assignments_activites_students
于 2012-08-11T07:13:11.407 回答