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

Conflicts:
	activerecord/CHANGELOG.md
This commit is contained in:
Yves Senn
2013-07-15 11:17:25 -07:00
committed by Rafael Mendonça França
parent 714cb5a436
commit 1c2545a455
2 changed files with 9 additions and 0 deletions

View File

@@ -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?)

View File

@@ -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}") }