This project is archived and is in readonly mode.
accepts_nested_attributes_for fails if nested attributes set from Class finders
-
Alexey Nayden
I can confirm that bug. That issue comes from #first behaviour which either loads first item from a database (when applicable) or loads the whole collection and merges it with in-memory changes. On the same time #[] method always uses the second way.
Here're a failing test and a patch to fix this issue and to make #[] and #first behave consistently.
-
Alexey Nayden
- No changes were found…
-
Alexey Nayden
- Assigned user set to Santiago Pastorino
-
Alexey Nayden
- Tag changed from accepts_nested_attributes_for, association, caching, first to accepts_nested_attributes_for, association, caching, first, patch
-
Aaron Patterson
- State changed from new to open
- Importance changed from to Low
@Alexey your patch makes the AR tests fail with:
1) Error: test_first_and_array_index_zero_methods_return_the_same_value_when_nested_attributes_are_set_to_update_existing_record(TestNestedAttributesInGeneral): ActiveRecord::RecordNotFound: Couldn't find Interest with ID=1059641603 for Man with ID=970345986 /Users/apatterson/git/rails/activerecord/lib/active_record/nested_attributes.rb:457:in `raise_nested_attributes_record_not_found' /Users/apatterson/git/rails/activerecord/lib/active_record/nested_attributes.rb:423:in `block in assign_nested_attributes_for_collection_association' /Users/apatterson/git/rails/activerecord/lib/active_record/nested_attributes.rb:399:in `each' /Users/apatterson/git/rails/activerecord/lib/active_record/nested_attributes.rb:399:in `assign_nested_attributes_for_collection_association' /Users/apatterson/git/rails/activerecord/lib/active_record/nested_attributes.rb:287:in `interests_attributes=' test/cases/nested_attributes_test.rb:156:in `test_first_and_array_index_zero_methods_return_the_same_value_when_nested_attributes_are_set_to_update_existing_record' /Users/apatterson/.local/lib/ruby/gems/1.9.1/gems/mocha-0.9.10/lib/mocha/integration/mini_test/version_142_and_above.rb:27:in `run' /Users/apatterson/git/rails/activesupport/lib/active_support/testing/setup_and_teardown.rb:35:in `block in run' /Users/apatterson/git/rails/activesupport/lib/active_support/callbacks.rb:411:in `_run_setup_callbacks' /Users/apatterson/git/rails/activesupport/lib/active_support/testing/setup_and_teardown.rb:34:in `run'Can you fix this and update the patch?
-
Alexey Nayden
@Aaron my bad. Patch fixed to work fine now. Sorry about that
-
Alexey Nayden
Ping anyone?
