aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/validations
diff options
context:
space:
mode:
authorScott Willson <scott.willson@gmail.com>2012-10-16 19:04:40 -0700
committerScott Willson <scott.willson@gmail.com>2012-10-16 19:04:40 -0700
commit25262bc280e8c9c0e875315958f82230b67cbf35 (patch)
tree48baee2cc9088c4eed11696e9c280718cf175211 /activerecord/lib/active_record/validations
parentc432c74cd34d4230bfda6fa008f2af9dbc33e523 (diff)
downloadrails-25262bc280e8c9c0e875315958f82230b67cbf35.tar.gz
rails-25262bc280e8c9c0e875315958f82230b67cbf35.tar.bz2
rails-25262bc280e8c9c0e875315958f82230b67cbf35.zip
Fix bug with presence validation of associations.
Would incorrectly add duplicated errors when the association was blank. Bug introduced in 1fab518c6a75dac5773654646eb724a59741bc13.
Diffstat (limited to 'activerecord/lib/active_record/validations')
-rw-r--r--activerecord/lib/active_record/validations/presence.rb6
1 files changed, 4 insertions, 2 deletions
diff --git a/activerecord/lib/active_record/validations/presence.rb b/activerecord/lib/active_record/validations/presence.rb
index 81a3521d24..6b14c39686 100644
--- a/activerecord/lib/active_record/validations/presence.rb
+++ b/activerecord/lib/active_record/validations/presence.rb
@@ -5,8 +5,10 @@ module ActiveRecord
super
attributes.each do |attribute|
next unless record.class.reflect_on_association(attribute)
- value = record.send(attribute)
- if Array(value).all? { |r| r.marked_for_destruction? }
+ associated_records = Array(record.send(attribute))
+
+ # Superclass validates presence. Ensure present records aren't about to be destroyed.
+ if associated_records.present? && associated_records.all? { |r| r.marked_for_destruction? }
record.errors.add(attribute, :blank, options)
end
end