diff options
author | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2013-10-10 14:41:37 -0300 |
---|---|---|
committer | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2013-10-10 14:55:12 -0300 |
commit | 38aefa51c35e0c7b117291c1cf0b7b4c148e7c5b (patch) | |
tree | e3d53ca9ee1df5ab8adb0daafa6b868c79a69af4 /activerecord | |
parent | fbc69ac5609aea9eab13fb01342272f812bce9d8 (diff) | |
download | rails-38aefa51c35e0c7b117291c1cf0b7b4c148e7c5b.tar.gz rails-38aefa51c35e0c7b117291c1cf0b7b4c148e7c5b.tar.bz2 rails-38aefa51c35e0c7b117291c1cf0b7b4c148e7c5b.zip |
Revert "Merge pull request #12413 from arthurnn/inverse_of_on_build"
This reverts commit ccd11d58910059f07b28cc518dbdad42cbc8ea0c, reversing
changes made to 54c05acdba138f3a7a3d44dfc922b0fe4e4cf554.
Reason: This caused a regression when the associated record is created
in a before_create callback. See
https://github.com/rails/rails/pull/12413#issuecomment-25848163
Diffstat (limited to 'activerecord')
4 files changed, 2 insertions, 10 deletions
diff --git a/activerecord/CHANGELOG.md b/activerecord/CHANGELOG.md index 5107e43b55..cf1f20c829 100644 --- a/activerecord/CHANGELOG.md +++ b/activerecord/CHANGELOG.md @@ -1,10 +1,4 @@ ## unreleased ## -* Move .set_inverse_instance call to association.build_record method. Everytime a new record is build - using the association, we need to try to set the inverse_of relation. - - Fixes #10371. - - *arthurnn* * When calling the method .find_or_initialize_by_* from a collection_proxy it should set the inverse_of relation even when the entry was found on the db. diff --git a/activerecord/lib/active_record/associations/association.rb b/activerecord/lib/active_record/associations/association.rb index 1e324c7e95..99f307922e 100644 --- a/activerecord/lib/active_record/associations/association.rb +++ b/activerecord/lib/active_record/associations/association.rb @@ -240,7 +240,6 @@ module ActiveRecord skip_assign = [reflection.foreign_key, reflection.type].compact attributes = create_scope.except(*(record.changed - skip_assign)) record.assign_attributes(attributes, :without_protection => true) - set_inverse_instance(record) end end end diff --git a/activerecord/lib/active_record/associations/collection_association.rb b/activerecord/lib/active_record/associations/collection_association.rb index c2dd462b5d..baddb9852f 100644 --- a/activerecord/lib/active_record/associations/collection_association.rb +++ b/activerecord/lib/active_record/associations/collection_association.rb @@ -350,6 +350,7 @@ module ActiveRecord end callback(:after_add, record) + set_inverse_instance(record) record end diff --git a/activerecord/test/cases/associations/inverse_associations_test.rb b/activerecord/test/cases/associations/inverse_associations_test.rb index 51e466ecac..0cab6faa25 100644 --- a/activerecord/test/cases/associations/inverse_associations_test.rb +++ b/activerecord/test/cases/associations/inverse_associations_test.rb @@ -125,10 +125,8 @@ class InverseHasOneTests < ActiveRecord::TestCase end def test_parent_instance_should_be_shared_with_newly_created_child - m = Man.create + m = Man.find(:first) f = m.create_face(:description => 'haunted') - - assert_equal m.object_id, f.man.object_id assert_not_nil f.man assert_equal m.name, f.man.name, "Name of man should be the same before changes to parent instance" m.name = 'Bongo' |