diff options
author | Bogdan Gusiev <agresso@gmail.com> | 2017-12-27 15:52:35 +0200 |
---|---|---|
committer | Bogdan Gusiev <agresso@gmail.com> | 2017-12-27 15:58:09 +0200 |
commit | a84c76573fa776e377c087930dcbdc3a07eb8603 (patch) | |
tree | 7ffd45b7ba527905a30799a8fa056cd90d5a8b3c /activerecord/test/cases | |
parent | 17ad4eb6fb25e0c1dbd6772718a9097d63b64ad2 (diff) | |
download | rails-a84c76573fa776e377c087930dcbdc3a07eb8603.tar.gz rails-a84c76573fa776e377c087930dcbdc3a07eb8603.tar.bz2 rails-a84c76573fa776e377c087930dcbdc3a07eb8603.zip |
Bugfix foreign key replacement in inverse association
when model is added to collection association
Diffstat (limited to 'activerecord/test/cases')
-rw-r--r-- | activerecord/test/cases/associations/has_many_associations_test.rb | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/activerecord/test/cases/associations/has_many_associations_test.rb b/activerecord/test/cases/associations/has_many_associations_test.rb index 5ed8d0ee81..0eafd3a4e2 100644 --- a/activerecord/test/cases/associations/has_many_associations_test.rb +++ b/activerecord/test/cases/associations/has_many_associations_test.rb @@ -2509,6 +2509,15 @@ class HasManyAssociationsTest < ActiveRecord::TestCase assert_same car, new_bulb.car end + test "reattach to new objects replaces inverse association and foreign key" do + bulb = Bulb.create!(car: Car.create!) + assert bulb.car_id + car = Car.new + car.bulbs << bulb + assert_equal car, bulb.car + assert_nil bulb.car_id + end + test "in memory replacement maintains order" do first_bulb = Bulb.create! second_bulb = Bulb.create! |