aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record
diff options
context:
space:
mode:
authorJosé Valim <jose.valim@gmail.com>2012-03-18 04:13:28 -0700
committerJosé Valim <jose.valim@gmail.com>2012-03-18 04:13:28 -0700
commitd802a6c275fa79d25173cda1c06764e6b0e87902 (patch)
tree06386eb5831995bef5b8726c9e84578ba5b07841 /activerecord/lib/active_record
parent0c18fafcdf5dea1681a67bf0e008c5368c579d8a (diff)
parentf1903d8db706beb6332398ac8baf13488a37e6f4 (diff)
downloadrails-d802a6c275fa79d25173cda1c06764e6b0e87902.tar.gz
rails-d802a6c275fa79d25173cda1c06764e6b0e87902.tar.bz2
rails-d802a6c275fa79d25173cda1c06764e6b0e87902.zip
Merge pull request #3329 from armstrjare/autosave_collection_new_record_bug
Autosave association doesn't save all records on a new record for a collection association if there are records marked for destruction
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 01d25b8867..3005bef092 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