diff options
author | Dmitry Polushkin <dmirty.polushkin@gmail.com> | 2009-07-11 18:46:11 +0200 |
---|---|---|
committer | Eloy Duran <eloy.de.enige@gmail.com> | 2009-09-12 15:56:01 +0200 |
commit | 845f62f4730fb9ab8847033f9ab7435c40006662 (patch) | |
tree | dfab1549b1df2276f35e3412e8da030342689151 /activerecord/lib/active_record | |
parent | 6cc0b9638fbb6ede3c46b51d7dab17881416014c (diff) | |
download | rails-845f62f4730fb9ab8847033f9ab7435c40006662.tar.gz rails-845f62f4730fb9ab8847033f9ab7435c40006662.tar.bz2 rails-845f62f4730fb9ab8847033f9ab7435c40006662.zip |
Fix autosave association to skip validation if it is marked for destruction. [#2064 state:resolved]
Signed-off-by: Eloy Duran <eloy.de.enige@gmail.com>
Diffstat (limited to 'activerecord/lib/active_record')
-rw-r--r-- | activerecord/lib/active_record/autosave_association.rb | 12 |
1 files changed, 5 insertions, 7 deletions
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, <tt>self</tt>, if it wasn't. Skips any <tt>:autosave</tt> - # 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) |