diff options
author | José Valim <jose.valim@gmail.com> | 2011-12-04 15:57:13 -0800 |
---|---|---|
committer | José Valim <jose.valim@gmail.com> | 2011-12-04 15:57:13 -0800 |
commit | cf6ccf0ebd632ae5a8d4fc3b30ba47eff9837eef (patch) | |
tree | 31c2d7914f343f8a4fa1065ebdd7b66930f2ec3e /activerecord/lib | |
parent | 4ded0dd2de4dca40fcb7ccbc215db4c098a6629d (diff) | |
parent | a8134aceb363d581d6b49aeb08feeadaf474d051 (diff) | |
download | rails-cf6ccf0ebd632ae5a8d4fc3b30ba47eff9837eef.tar.gz rails-cf6ccf0ebd632ae5a8d4fc3b30ba47eff9837eef.tar.bz2 rails-cf6ccf0ebd632ae5a8d4fc3b30ba47eff9837eef.zip |
Merge pull request #3854 from exviva/validates_associated_marked_for_destruction
Do not validate associated records marked for destruction
Diffstat (limited to 'activerecord/lib')
-rw-r--r-- | activerecord/lib/active_record/validations/associated.rb | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/activerecord/lib/active_record/validations/associated.rb b/activerecord/lib/active_record/validations/associated.rb index 7af0352a31..9f072c4c39 100644 --- a/activerecord/lib/active_record/validations/associated.rb +++ b/activerecord/lib/active_record/validations/associated.rb @@ -2,8 +2,9 @@ module ActiveRecord module Validations class AssociatedValidator < ActiveModel::EachValidator def validate_each(record, attribute, value) - return if (value.is_a?(Array) ? value : [value]).collect{ |r| r.nil? || r.valid? }.all? - record.errors.add(attribute, :invalid, options.merge(:value => value)) + if Array.wrap(value).reject {|r| r.marked_for_destruction? || r.valid?}.any? + record.errors.add(attribute, :invalid, options.merge(:value => value)) + end end end |