aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record
diff options
context:
space:
mode:
authorJared Armstrong <jared.armstrong@gmail.com>2011-10-15 00:49:55 +1300
committerJared Armstrong <jared.armstrong@gmail.com>2012-03-18 20:20:01 +1300
commitf1903d8db706beb6332398ac8baf13488a37e6f4 (patch)
tree18e22cfff28fc23728069508fcfe23bf1f04d03f /activerecord/lib/active_record
parentfa7a3aaac734da7efef17039a934154f64144796 (diff)
downloadrails-f1903d8db706beb6332398ac8baf13488a37e6f4.tar.gz
rails-f1903d8db706beb6332398ac8baf13488a37e6f4.tar.bz2
rails-f1903d8db706beb6332398ac8baf13488a37e6f4.zip
Fix bug with autosave collection association on new record with a marked for destroy record in autosave collection.
Diffstat (limited to 'activerecord/lib/active_record')
-rw-r--r--activerecord/lib/active_record/autosave_association.rb7
1 files changed, 6 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/autosave_association.rb b/activerecord/lib/active_record/autosave_association.rb
index be0af081d1..f0cfa667ed 100644
--- a/activerecord/lib/active_record/autosave_association.rb
+++ b/activerecord/lib/active_record/autosave_association.rb
@@ -328,13 +328,14 @@ module ActiveRecord
autosave = reflection.options[:autosave]
if records = associated_records_to_validate_or_save(association, @new_record_before_save, autosave)
+ records_to_destroy = []
records.each do |record|
next if record.destroyed?
saved = true
if autosave && record.marked_for_destruction?
- association.proxy.destroy(record)
+ records_to_destroy << record
elsif autosave != false && (@new_record_before_save || record.new_record?)
if autosave
saved = association.insert_record(record, false)
@@ -347,6 +348,10 @@ module ActiveRecord
raise ActiveRecord::Rollback unless saved
end
+
+ records_to_destroy.each do |record|
+ association.proxy.destroy(record)
+ end
end
# reconstruct the scope now that we know the owner's id