This project is archived and is in readonly mode.
Updates to relationship resources are lost
Reported by Sam Ruby | June 11th, 2010 @ 04:04 PM | in 3.0.2
Updates to a line_item resource which relates a product to a cart are lost.
Broken by commit 0265c708b9696c3943518ad5f3dabdc22c5eba11
Comments and changes to this ticket
-
Repository June 11th, 2010 @ 04:07 PM
(from [85cc1fa657f441417f36998a32a6a158c2697aad]) Revert "Don't overwrite unsaved updates when loading an association but preserve the order of the loaded records. [#4642 state:open]"
This commit introduced a regression described in ticket [#4830].
This reverts commit 0265c708b9696c3943518ad5f3dabdc22c5eba11.
http://github.com/rails/rails/commit/85cc1fa657f441417f36998a32a6a1... -
James Le Cuirot June 11th, 2010 @ 04:15 PM
Hmm sorry about that. I was trying to fix another bug. I'll look into it as soon as I can.
-
James Le Cuirot June 12th, 2010 @ 10:35 AM
Figured it out and have a fix. I'll post it with an AR testcase shortly.
-
James Le Cuirot June 12th, 2010 @ 12:03 PM
The updates were not lost entirely as they were still saved to the database. They just weren't reflected in the model immediately afterwards. By keeping my previous fix but allowing already-saved records to be refreshed, everything is okay.
The first attachment is against 2-3-stable where my original commit was not reverted.
The second attachment is against master and reapplies the original commit along with the new fix. I have not got Rails 3 going yet and don't have time to do that today (had trouble when I last tried) so please run the tests to ensure it works.
-
José Valim June 17th, 2010 @ 04:34 PM
- Milestone cleared.
- Assigned user set to José Valim
-
Repository June 19th, 2010 @ 11:33 PM
- State changed from open to resolved
(from [f664c57fe854c230d25c448b941569b81860fa79]) Don't overwrite unsaved updates when loading an association but preserve the order of the loaded records. Reapplied from before but now allows already-saved records to be refreshed.
[#4830 state:resolved]
Signed-off-by: José Valim jose.valim@gmail.com
http://github.com/rails/rails/commit/f664c57fe854c230d25c448b941569... -
helg June 30th, 2010 @ 11:02 AM
- Importance changed from to High
I'm still loosing _destroy attribute after accessing to collection
-
James Le Cuirot June 30th, 2010 @ 11:09 AM
I'm having a crisis this morning but I'll try and look into this tonight.
-
szetobo July 8th, 2010 @ 08:13 AM
By looking into the test case, the protected function :load_target must be called using send(:load_target) in order to retrieve the association collection together with the changes made by nested attributes assignment. Is it a desirable way to interact with Rails framework?
Since I need to re-display the record (with nested attributes) on the input form upon validation error, I can only calling send(:load_target) all around in order to prevent the association collection reload from db and wipe out any changes. My problem case described here #5053.
-
James Le Cuirot July 8th, 2010 @ 09:22 AM
You don't have to call
send(:load_target)
. I think we only do that in the tests because we need to callfind
on the array itself, not ActiveRecord's find. If we were to dotarget.find
instead, it wouldn't actually load the collection.I haven't looked at your particular case but it sounds like the same problem I have already fixed. It should work fine with master or 2-3-stable now.
-
szetobo July 8th, 2010 @ 10:18 AM
We have a form to edit master-child-grandchild record at the same time using nested_attributes. When the form submit, I call master.update_attributes(params[:master]) and the validation callback is invoked. During the validation handler, I must access the submit data instead of data reload from db and that's why I need to access the association array instead of ActiveRecord's find from db.
Also, if validation failed, I need to re-display the whole form together with error message and with error field highlight. Doing so also need to access the association array instead of refresh data from db.
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="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>
People watching this ticket
Attachments
Referenced by
- 4642 Unsaved changes to nested attribute collections are lost when using collection This commit introduced a regression described in ticket [...
- 4830 Updates to relationship resources are lost This commit introduced a regression described in ticket [...
- 4642 Unsaved changes to nested attribute collections are lost when using collection Sam attached a failing scenario at ticket #4830. Could so...
- 4642 Unsaved changes to nested attribute collections are lost when using collection Don't worry, I have fixed the above failure in a way that...
- 4830 Updates to relationship resources are lost [#4830 state:resolved]
- 5053 child/grandchild associations reload from db after nested attributes assignment Some discussion regarded nested_attribute took place on #...