Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

undefined method `updated?' for HasOneAssociation , for nested attributes in Rails 4

so my problem is like:

https://gist.github.com/panSarin/4a221a0923927115584a

when i save this form i get error like in title

NoMethodError (undefined method `updated?' for 
#ActiveRecord::Associations::HasOneAssociation:0x00000008fcacf8>):

I checked without polymorphic association - and it`s the same.

When the parent model (BusinessClient in that case) have belongs_to then it works fine. But i can't belive that i can't have architecture that children keeps parent_id . Any idea what should i change to make it works ?

like image 621
Adam Piotrowski Avatar asked Jan 08 '14 16:01

Adam Piotrowski


1 Answers

EDIT

Actually, I had defined the relation twice in my case, once as belongs_to, once as has_one_through. Long day :) Arthur's answer should be the accepted one!

Previous answer:

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

I think it might be an ActiveRecord bug.

Autosave calls updated? on associations, which is defined for belongs_to, but not for has_one (or has_one_through).

like image 148
rmosolgo Avatar answered Oct 12 '22 10:10

rmosolgo