diff options
author | Yves Senn <yves.senn@gmail.com> | 2013-07-15 11:17:25 -0700 |
---|---|---|
committer | Yves Senn <yves.senn@gmail.com> | 2013-07-15 11:17:25 -0700 |
commit | a618e9e9ddf4b1900c9288625eaa2a9b444dc0c5 (patch) | |
tree | 1b494bbe1a2c6e7bc5c3d48e0a315c772f9e1b58 | |
parent | d7a1f98d8c237aabcd5a3f315fe00c7a43836209 (diff) | |
parent | 372e809667b37f11e232a762815211601859b8b5 (diff) | |
download | rails-a618e9e9ddf4b1900c9288625eaa2a9b444dc0c5.tar.gz rails-a618e9e9ddf4b1900c9288625eaa2a9b444dc0c5.tar.bz2 rails-a618e9e9ddf4b1900c9288625eaa2a9b444dc0c5.zip |
Merge pull request #11451 from jetthoughts/11450_do_not_resave_destroyed_association
Do not re-save destroyed association on saving parent object
-rw-r--r-- | activerecord/lib/active_record/autosave_association.rb | 1 | ||||
-rw-r--r-- | activerecord/test/cases/autosave_association_test.rb | 7 |
2 files changed, 8 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/autosave_association.rb b/activerecord/lib/active_record/autosave_association.rb index a8a1847554..c991c870ed 100644 --- a/activerecord/lib/active_record/autosave_association.rb +++ b/activerecord/lib/active_record/autosave_association.rb @@ -343,6 +343,7 @@ module ActiveRecord end records.each do |record| + next if record.destroyed? saved = true diff --git a/activerecord/test/cases/autosave_association_test.rb b/activerecord/test/cases/autosave_association_test.rb index 580aa96ecd..635278abc1 100644 --- a/activerecord/test/cases/autosave_association_test.rb +++ b/activerecord/test/cases/autosave_association_test.rb @@ -705,6 +705,13 @@ class TestDestroyAsPartOfAutosaveAssociation < ActiveRecord::TestCase ids.each { |id| assert_nil klass.find_by_id(id) } end + def test_should_not_resave_destroyed_association + @pirate.birds.create!(name: :parrot) + @pirate.birds.first.destroy + @pirate.save! + assert @pirate.reload.birds.empty? + end + def test_should_skip_validation_on_has_many_if_marked_for_destruction 2.times { |i| @pirate.birds.create!(:name => "birds_#{i}") } |