diff options
author | Ryuta Kamizono <kamipo@gmail.com> | 2018-01-01 01:40:24 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-01-01 01:40:24 +0900 |
commit | 79284012e920a80adfbf486e731c285788bde4ed (patch) | |
tree | d28a6387b14bc2cde4503332e9c3ca055b7bfcbc /activerecord/test/cases/associations | |
parent | 540c60ff4723670bf106c2ae46e3a6723cbf42a4 (diff) | |
parent | a84c76573fa776e377c087930dcbdc3a07eb8603 (diff) | |
download | rails-79284012e920a80adfbf486e731c285788bde4ed.tar.gz rails-79284012e920a80adfbf486e731c285788bde4ed.tar.bz2 rails-79284012e920a80adfbf486e731c285788bde4ed.zip |
Merge pull request #31575 from bogdan/bugfix-has-many-reattachment
Bugfix foreign key replacement in inverse association
Diffstat (limited to 'activerecord/test/cases/associations')
-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! |