我一直在敲打这个问题。在同时保存新引荐(父对象)和约会(子)时会出现问题。我已经完成了与其他嵌套对象类似但似乎无法使其与单表继承 - 约会表一起使用。出于某种原因,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|
感谢任何帮助。
答案 0 :(得分:0)
在class_name
子句中使用referral
belongs_to
怎么样?像这样:
class Appointment::Base < ActiveRecord::Base
...
belongs_to :referral, class_name: 'Referral', inverse_of: :appointments
end
对于Base
Appointment
(Referral
)在同一名称空间中查找