diff options
author | Yves Senn <yves.senn@gmail.com> | 2013-07-15 11:17:25 -0700 |
---|---|---|
committer | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2013-07-15 15:48:43 -0300 |
commit | 2ae2728d78298030b1015497840b0519b5ed21a1 (patch) | |
tree | ceeffeed132ea0b8831ecf4ff29e5741887dc198 | |
parent | facfc24f256d8367f33a62e3bbea6c0f8c698c1f (diff) | |
download | rails-2ae2728d78298030b1015497840b0519b5ed21a1.tar.gz rails-2ae2728d78298030b1015497840b0519b5ed21a1.tar.bz2 rails-2ae2728d78298030b1015497840b0519b5ed21a1.zip |
Merge pull request #11451 from jetthoughts/11450_do_not_resave_destroyed_association
Do not re-save destroyed association on saving parent object
Conflicts:
activerecord/lib/active_record/autosave_association.rb
-rw-r--r-- | activerecord/CHANGELOG.md | 9 | ||||
-rw-r--r-- | activerecord/lib/active_record/autosave_association.rb | 2 | ||||
-rw-r--r-- | activerecord/test/cases/autosave_association_test.rb | 7 |
3 files changed, 18 insertions, 0 deletions
diff --git a/activerecord/CHANGELOG.md b/activerecord/CHANGELOG.md index 37adce4f30..59f670dd4a 100644 --- a/activerecord/CHANGELOG.md +++ b/activerecord/CHANGELOG.md @@ -1,3 +1,12 @@ +## Rails 3.2.14.rc2 (unreleased) ## + +* Do not re-create destroyed association when saving the parent object. + + Fixes #11450. + + *Paul Nikitochkin* + + ## Rails 3.2.14.rc1 (Jul 8, 2013) ## * Do not shallow the original exception in `exec_cache` on PostgreSQL adapter. diff --git a/activerecord/lib/active_record/autosave_association.rb b/activerecord/lib/active_record/autosave_association.rb index 3fc9d307bc..4da39299f0 100644 --- a/activerecord/lib/active_record/autosave_association.rb +++ b/activerecord/lib/active_record/autosave_association.rb @@ -339,6 +339,8 @@ module ActiveRecord end records.each do |record| + next if record.destroyed? + saved = true if autosave != false && (@new_record_before_save || record.new_record?) diff --git a/activerecord/test/cases/autosave_association_test.rb b/activerecord/test/cases/autosave_association_test.rb index 6dbc419eb5..5556ab8fcc 100644 --- a/activerecord/test/cases/autosave_association_test.rb +++ b/activerecord/test/cases/autosave_association_test.rb @@ -734,6 +734,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}") } |