From 845f62f4730fb9ab8847033f9ab7435c40006662 Mon Sep 17 00:00:00 2001 From: Dmitry Polushkin Date: Sat, 11 Jul 2009 18:46:11 +0200 Subject: Fix autosave association to skip validation if it is marked for destruction. [#2064 state:resolved] Signed-off-by: Eloy Duran --- activerecord/lib/active_record/autosave_association.rb | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) (limited to 'activerecord/lib/active_record/autosave_association.rb') diff --git a/activerecord/lib/active_record/autosave_association.rb b/activerecord/lib/active_record/autosave_association.rb index aff29dcc4e..10dd0b4f05 100644 --- a/activerecord/lib/active_record/autosave_association.rb +++ b/activerecord/lib/active_record/autosave_association.rb @@ -243,17 +243,15 @@ module ActiveRecord # Returns whether or not the association is valid and applies any errors to # the parent, self, if it wasn't. Skips any :autosave - # enabled records if they're marked_for_destruction?. + # enabled records if they're marked_for_destruction? or destroyed. def association_valid?(reflection, association) - return true if association.destroyed? + return true if association.destroyed? || association.marked_for_destruction? unless valid = association.valid? if reflection.options[:autosave] - unless association.marked_for_destruction? - association.errors.each do |attribute, message| - attribute = "#{reflection.name}_#{attribute}" - errors[attribute] << message if errors[attribute].empty? - end + association.errors.each do |attribute, message| + attribute = "#{reflection.name}_#{attribute}" + errors[attribute] << message if errors[attribute].empty? end else errors.add(reflection.name) -- cgit v1.2.3