This project is archived and is in readonly mode.

#4766 ✓duplicate
Luke Melia

nested_attributes fails to update/destroy when association is loaded between setting attributes and saving parent

Reported by Luke Melia | June 4th, 2010 @ 04:47 PM | in 2.3.10

Commit 5efb1503dd88b59fe491dade92790c3f06293445 introduced behavior to avoid loading all records of a has_many association when using nested_attributes. This commit causes surprising behavior: if you trigger a load of the association after setting the attributes but before saving, the instances with the changes/mark_for_destruction will be replaced with fresh instances from the DB, thereby losing the desired changes.

I'm not sure if this would be considered a bug, but it is changed behavior from 2.3.5 and is silent and surprising.

I've attached a patch with failing tests, but I am looking for ideas for a solution. In my app, I have hacked around it by forcing the load of the relevant associations before assigning attributes.

Note: This issue was introduced on the rails-core list here:

Comments and changes to this ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href=""></a>


Referenced by