This project is archived and is in readonly mode.
When using accepts_nested_attributes_for, update_attributes! on association doesn't call after_update callback
-
Emmanuel Nicolau
- Title changed from When using accepts_nested_attributes_for update_attributes! on association doesn't call after_update callback to When using accepts_nested_attributes_for, update_attributes! on association doesn't call after_update callback
-
Eloy Duran
- Assigned user set to Eloy Duran
- State changed from new to open
- Milestone cleared.
-
Eloy Duran
- Milestone set to 2.x
-
Emmanuel Nicolau
update_attributes! doesn't call after_save either.
-
rdavila
This works fine for me in Rails 2.3.5 and Ruby 1.8.7, and the correct syntax is:
p.update_attributes! :name => "Smith29", :children_attributes => [{ :id => p.children.first.id, :name => "John" }] -
Chris Flipse
This actually looks like it's not a bug -- it's the dirty attributes behaving correctly
p = Person.create!(:name => "Smith", :children_attributes => {"new_1" => {:name => "John"}}) # after save # => #<Person id: 3 ...> p.update_attributes! :name => "Smith29", :children_attributes => [{ :id => p.children.first.id, :name => "John" }] # => true p.update_attributes! :name => "Smith30", :children_attributes => [{ :id => p.children.first.id, :name => "Joe" }] after update after save # => trueFirst update doesn't actually change the child's attributes, so it's never marked as dirty, so it's never acutally saved.
Second update changes the child's attributes, and the callbacks work fine.
-
Jeremy Kemper
- State changed from open to invalid