4

我已经在这个问题上敲了一段时间。同时保存新的推荐(父对象)和约会(子对象)时会出现问题。我对其他嵌套对象做过类似的事情,但似乎无法让它与单表继承——约会表一起工作。由于某种原因, inverse_of 不会将新推荐人的 id 传递给约会。

class Referral < ActiveRecord::Base

  has_many :appointments, class_name: 'Appointment::Base', inverse_of: :referral

  accepts_nested_attributes_for :appointments

end

class Appointment::Base < ActiveRecord::Base

  self.table_name = 'appointments'

  belongs_to :referral, inverse_of: :appointments

end

在视图中

fields_for :appointments do |a|

任何帮助表示赞赏。

4

1 回答 1

1

在子句中使用class_namefor怎么样?像这样:referralbelongs_to

class Appointment::Base < ActiveRecord::Base
  ...
  belongs_to :referral, class_name: 'Referral', inverse_of: :appointments
end

Rails 可能在与Base( Appointment)相同的命名空间中查找Referral

于 2013-12-18T20:33:15.127 回答