mirror of
https://github.com/github/rails.git
synced 2026-01-09 14:48:01 -05:00
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
This commit is contained in:
committed by
Rafael Mendonça França
parent
facfc24f25
commit
2ae2728d78
@@ -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.
|
||||
|
||||
@@ -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?)
|
||||
|
||||
@@ -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}") }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user