1

我有以下型号 -

class Employee < ActiveRecord::Base
  has_and_belongs_to_many :surveys, join_table: 'employee_surveys'
end


class Survey < ActiveRecord::Base
  has_and_belongs_to_many :employees, join_table: 'employee_surveys'
end

当我这样做时Employee.first.surveys.create(name: "New Survey"),它会产生一个错误,抱怨employee_idnull??

4

1 回答 1

1

我认为您想在这里使用员工类的实例,而不是类本身。

喜欢:

employee = Employee.first
employee.surveys.create(name: "New Survey")
于 2012-06-28T03:17:32.220 回答