Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Revert "Merge pull request #12413 from arthurnn/inverse_of_on_build"

This reverts commit ccd11d5, reversing
changes made to 54c05ac.

Reason: This caused a regression when the associated record is created
in a before_create callback. See
#12413 (comment)
  • Loading branch information...
commit 38aefa51c35e0c7b117291c1cf0b7b4c148e7c5b 1 parent fbc69ac
@rafaelfranca rafaelfranca authored
View
6 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.
View
1  activerecord/lib/active_record/associations/association.rb
@@ -240,7 +240,6 @@ def build_record(attributes, options)
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
View
1  activerecord/lib/active_record/associations/collection_association.rb
@@ -350,6 +350,7 @@ def add_to_target(record)
end
callback(:after_add, record)
+ set_inverse_instance(record)
record
end
View
4 activerecord/test/cases/associations/inverse_associations_test.rb
@@ -125,10 +125,8 @@ def test_parent_instance_should_be_shared_with_newly_built_child
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'
Please sign in to comment.
Something went wrong with that request. Please try again.