diff options
author | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2013-10-04 09:57:17 -0700 |
---|---|---|
committer | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2013-10-04 13:58:36 -0300 |
commit | 73dff261259913272816d855fb9715790f87f578 (patch) | |
tree | 81b687dbac3f8d27e3ff5269bd284bf7524738db | |
parent | 5e277c82085f6258b6aa4a19a90c6ea46686af84 (diff) | |
download | rails-73dff261259913272816d855fb9715790f87f578.tar.gz rails-73dff261259913272816d855fb9715790f87f578.tar.bz2 rails-73dff261259913272816d855fb9715790f87f578.zip |
Merge pull request #12443 from arthurnn/add_inverse_of_add_target
Add inverse of add target
-rw-r--r-- | activerecord/lib/active_record/associations/collection_association.rb | 1 | ||||
-rw-r--r-- | activerecord/test/cases/associations/inverse_associations_test.rb | 13 |
2 files changed, 14 insertions, 0 deletions
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..a44b78f200 100644 --- a/activerecord/test/cases/associations/inverse_associations_test.rb +++ b/activerecord/test/cases/associations/inverse_associations_test.rb @@ -290,6 +290,19 @@ class InverseHasManyTests < ActiveRecord::TestCase def test_trying_to_use_inverses_that_dont_exist_should_raise_an_error assert_raise(ActiveRecord::InverseOfAssociationNotFoundError) { Man.find(:first).secret_interests } end + + def test_child_instance_should_point_to_parent_without_saving + man = Man.new + i = Interest.create(:topic => 'Industrial Revolution Re-enactment') + + man.interests << i + assert_not_nil i.man + + i.man.name = "Charles" + assert_equal i.man.name, man.name + + assert !man.persisted? + end end class InverseBelongsToTests < ActiveRecord::TestCase |