diff options
author | José Valim <jose.valim@gmail.com> | 2012-01-17 00:27:39 -0800 |
---|---|---|
committer | José Valim <jose.valim@gmail.com> | 2012-01-17 00:27:39 -0800 |
commit | 5f8274efe128ffeec8fa3179460f5167a078f007 (patch) | |
tree | 8a53a4bdb2749ae10c1145fcd9fe0a23e9ecce88 /activerecord/lib | |
parent | 81e837e810460d066a2e5fc5a795366ec8ab2313 (diff) | |
parent | 9b15e01c219013825275e7e10140d9883d148c8c (diff) | |
download | rails-5f8274efe128ffeec8fa3179460f5167a078f007.tar.gz rails-5f8274efe128ffeec8fa3179460f5167a078f007.tar.bz2 rails-5f8274efe128ffeec8fa3179460f5167a078f007.zip |
Merge pull request #4490 from EmmanuelOga/master
when validating a record, if a validation context is used, use the same context when validating related records
Diffstat (limited to 'activerecord/lib')
-rw-r--r-- | activerecord/lib/active_record/autosave_association.rb | 2 | ||||
-rw-r--r-- | activerecord/lib/active_record/validations/associated.rb | 2 |
2 files changed, 2 insertions, 2 deletions
diff --git a/activerecord/lib/active_record/autosave_association.rb b/activerecord/lib/active_record/autosave_association.rb index 8031912669..d468663084 100644 --- a/activerecord/lib/active_record/autosave_association.rb +++ b/activerecord/lib/active_record/autosave_association.rb @@ -295,7 +295,7 @@ module ActiveRecord def association_valid?(reflection, record) return true if record.destroyed? || record.marked_for_destruction? - unless valid = record.valid? + unless valid = record.valid?(validation_context) if reflection.options[:autosave] record.errors.each do |attribute, message| attribute = "#{reflection.name}.#{attribute}" diff --git a/activerecord/lib/active_record/validations/associated.rb b/activerecord/lib/active_record/validations/associated.rb index 9f072c4c39..afce149da9 100644 --- a/activerecord/lib/active_record/validations/associated.rb +++ b/activerecord/lib/active_record/validations/associated.rb @@ -2,7 +2,7 @@ module ActiveRecord module Validations class AssociatedValidator < ActiveModel::EachValidator def validate_each(record, attribute, value) - if Array.wrap(value).reject {|r| r.marked_for_destruction? || r.valid?}.any? + if Array.wrap(value).reject {|r| r.marked_for_destruction? || r.valid?(record.validation_context) }.any? record.errors.add(attribute, :invalid, options.merge(:value => value)) end end |