aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib
diff options
context:
space:
mode:
authorEloy Duran <eloy.de.enige@gmail.com>2009-02-26 11:56:27 +0100
committerDavid Heinemeier Hansson <david@loudthinking.com>2009-02-27 13:57:27 +0100
commite2b925fa68203607fb4f9a9aa457c0435c969f9a (patch)
treeed6f1e22f27aa7ccffb1d8b5d6609ac732b1ca17 /activerecord/lib
parent3d1d422b8be027417cb640416d154171e75f03d1 (diff)
downloadrails-e2b925fa68203607fb4f9a9aa457c0435c969f9a.tar.gz
rails-e2b925fa68203607fb4f9a9aa457c0435c969f9a.tar.bz2
rails-e2b925fa68203607fb4f9a9aa457c0435c969f9a.zip
Don't validate records of an :autosave association if they're marked for destruction. [#2064 status:resolved]
Signed-off-by: David Heinemeier Hansson <david@loudthinking.com>
Diffstat (limited to 'activerecord/lib')
-rw-r--r--activerecord/lib/active_record/autosave_association.rb11
1 files changed, 7 insertions, 4 deletions
diff --git a/activerecord/lib/active_record/autosave_association.rb b/activerecord/lib/active_record/autosave_association.rb
index 6e09b13150..1c3d0567c1 100644
--- a/activerecord/lib/active_record/autosave_association.rb
+++ b/activerecord/lib/active_record/autosave_association.rb
@@ -243,13 +243,16 @@ module ActiveRecord
end
# Returns whether or not the association is valid and applies any errors to
- # the parent, <tt>self</tt>, if it wasn't.
+ # the parent, <tt>self</tt>, if it wasn't. Skips any <tt>:autosave</tt>
+ # enabled records if they're marked_for_destruction?.
def association_valid?(reflection, association)
unless valid = association.valid?
if reflection.options[:autosave]
- association.errors.each do |attribute, message|
- attribute = "#{reflection.name}_#{attribute}"
- errors.add(attribute, message) unless errors.on(attribute)
+ unless association.marked_for_destruction?
+ association.errors.each do |attribute, message|
+ attribute = "#{reflection.name}_#{attribute}"
+ errors.add(attribute, message) unless errors.on(attribute)
+ end
end
else
errors.add(reflection.name)