我正在尝试创建一个表单来编辑由 has_one 通过关系链接的 2 个对象:
bank_acount.rb
class BankAccount < ActiveRecord::Base
belongs_to :user, inverse_of: :bank_account
has_one :personal_information, through: :user
accepts_nested_attributes_for :personal_information
accepts_nested_attributes_for :user
#...
end
个人信息.rb
class PersonalInformation < ActiveRecord::Base
belongs_to :user, inverse_of: :personal_information
#...
end
用户.rb
class User < ActiveRecord::Base
has_one :personal_information, inverse_of: :user
has_one :bank_account, inverse_of: :user
accepts_nested_attributes_for :personal_information
#...
end
当我尝试提交我的表单时(这是一个模拟的测试)
bank_account.update({:iban => 'XXX', :bic => 'XXX', personal_information_attributes: {
first_name: 'first name',
last_name: 'last name',
address: 'address',
zip: 'zip',
city: 'city'
}})
我收到此错误:
ArgumentError: Cannot build association `personal_information'. Are you trying to build a polymorphic one-to-one association?
我对多态的东西什么都不做,我不知道这个错误是从哪里来的。
任何想法?