aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/autosave_association.rb
diff options
context:
space:
mode:
authorEloy Duran <eloy.de.enige@gmail.com>2009-07-11 20:52:03 +0200
committerEloy Duran <eloy.de.enige@gmail.com>2009-09-12 16:04:07 +0200
commit65f98951ac5fe75191c6fde996b9e0f9b765414f (patch)
treec5ecf346361463edee98aa7d83b56eb8862c73ac /activerecord/lib/active_record/autosave_association.rb
parentc01be9de322ba846923340e41e69821d01541610 (diff)
downloadrails-65f98951ac5fe75191c6fde996b9e0f9b765414f.tar.gz
rails-65f98951ac5fe75191c6fde996b9e0f9b765414f.tar.bz2
rails-65f98951ac5fe75191c6fde996b9e0f9b765414f.zip
During autosave, ignore records that already have been destroyed. [#2537 state:resolved]
Diffstat (limited to 'activerecord/lib/active_record/autosave_association.rb')
-rw-r--r--activerecord/lib/active_record/autosave_association.rb6
1 files changed, 4 insertions, 2 deletions
diff --git a/activerecord/lib/active_record/autosave_association.rb b/activerecord/lib/active_record/autosave_association.rb
index 75c49ecb2b..bfae5933ea 100644
--- a/activerecord/lib/active_record/autosave_association.rb
+++ b/activerecord/lib/active_record/autosave_association.rb
@@ -281,6 +281,8 @@ module ActiveRecord
if records = associated_records_to_validate_or_save(association, @new_record_before_save, autosave)
records.each do |record|
+ next if record.destroyed?
+
if autosave && record.marked_for_destruction?
association.destroy(record)
elsif autosave != false && (@new_record_before_save || record.new_record?)
@@ -309,7 +311,7 @@ module ActiveRecord
# This all happens inside a transaction, _if_ the Transactions module is included into
# ActiveRecord::Base after the AutosaveAssociation module, which it does by default.
def save_has_one_association(reflection)
- if (association = association_instance_get(reflection.name)) && !association.target.nil?
+ if (association = association_instance_get(reflection.name)) && !association.target.nil? && !association.destroyed?
autosave = reflection.options[:autosave]
if autosave && association.marked_for_destruction?
@@ -333,7 +335,7 @@ module ActiveRecord
# This all happens inside a transaction, _if_ the Transactions module is included into
# ActiveRecord::Base after the AutosaveAssociation module, which it does by default.
def save_belongs_to_association(reflection)
- if association = association_instance_get(reflection.name)
+ if (association = association_instance_get(reflection.name)) && !association.destroyed?
autosave = reflection.options[:autosave]
if autosave && association.marked_for_destruction?