This project is archived and is in readonly mode.
Updates to relationship resources are lost
-
Repository
(from [85cc1fa657f441417f36998a32a6a158c2697aad]) Revert "Don't overwrite unsaved updates when loading an association but preserve the order of the loaded records. [#4642 Unsaved changes to nested attribute collections are lost when using collection state:open]"
This commit introduced a regression described in ticket [#4830 Updates to relationship resources are lost].
This reverts commit 0265c708b9696c3943518ad5f3dabdc22c5eba11.
http://github.com/rails/rails/commit/85cc1fa657f441417f36998a32a6a1... -
James Le Cuirot
Hmm sorry about that. I was trying to fix another bug. I'll look into it as soon as I can.
-
James Le Cuirot
Figured it out and have a fix. I'll post it with an AR testcase shortly.
-
James Le Cuirot
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
- Milestone cleared.
- Assigned user set to José Valim
-
Repository
- 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 Updates to relationship resources are lost state:resolved]
Signed-off-by: José Valim jose.valim@gmail.com
http://github.com/rails/rails/commit/f664c57fe854c230d25c448b941569... -
helg
- Importance changed from to High
I'm still loosing _destroy attribute after accessing to collection
-
James Le Cuirot
I'm having a crisis this morning but I'll try and look into this tonight.
-
szetobo
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 child/grandchild associations reload from db after nested attributes assignment.
-
James Le Cuirot
You don't have to call
send(:load_target). I think we only do that in the tests because we need to callfindon the array itself, not ActiveRecord's find. If we were to dotarget.findinstead, 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
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.
