Ada*_*ski 6 ruby-on-rails has-one nested-attributes
所以我的问题是:
https://gist.github.com/panSarin/4a221a0923927115584a
当我保存这个表格时,我得到像标题中的错误
NoMethodError (undefined method `updated?' for
#ActiveRecord::Associations::HasOneAssociation:0x00000008fcacf8>):
Run Code Online (Sandbox Code Playgroud)
我检查没有多态关联 - 它是相同的.
当父模型(在那种情况下是BusinessClient)有belongs_to它然后它工作正常.但我无法相信我不能拥有孩子们所拥有的建筑parent_id.知道我应该改变什么使其有效?
rmo*_*lgo 10
实际上,我已经在我的案例中定义了两次关系,一次为belongs_to,一次为has_one_through.漫长的一天:)亚瑟的答案应该是被接受的答案!
上一个答案:
Just had the same problem and worked it out. I had this:
has_one :organization, through: :event
I switched it to this:
has_one: organization, through: :event, autosave: false
Run Code Online (Sandbox Code Playgroud)
我认为这可能是一个ActiveRecord错误.
自动保存调用updated?关联,这是为(或)定义的belongs_to,但不是has_one(或has_one_through).
看一下要点,错误似乎是:client关联的定义:
belongs_to :client, foreign_key: :arch_crm_client_id
has_one :client, as: :client_details
Run Code Online (Sandbox Code Playgroud)
您正在尝试使用相同的名称定义2个关系,这会使ActiveRecord失败.要解决此问题,您需要重命名其中一个关联.
| 归档时间: |
|
| 查看次数: |
1729 次 |
| 最近记录: |