Class: ActiveRecord::Validations::AssociatedValidator
Do not use. This class is for internal use only.
Relationships & Source Files | |
Super Chains via Extension / Inclusion / Inheritance | |
Class Chain:
|
|
Instance Chain:
|
|
Inherits: |
ActiveModel::EachValidator
|
Defined in: | activerecord/lib/active_record/validations/associated.rb |
Class Method Summary
::ActiveModel::EachValidator
- Inherited
.new | Returns a new validator instance. |
::ActiveModel::Validator
- Inherited
Instance Attribute Summary
Instance Method Summary
- #validate_each(record, attribute, value)
- #record_validation_context_for_association(record) private
- #valid_object?(record, context) ⇒ Boolean private
::ActiveModel::EachValidator
- Inherited
#check_validity! | Hook method that gets called by the initializer allowing verification that the arguments supplied are valid. |
#validate | Performs validation on the supplied record. |
#validate_each | Override this method in subclasses with the validation logic, adding errors to the records |
#prepare_value_for_validation |
::ActiveModel::Validator
- Inherited
Constructor Details
This class inherits a constructor from ActiveModel::EachValidator
Instance Method Details
#record_validation_context_for_association(record) (private)
[ GitHub ]# File 'activerecord/lib/active_record/validations/associated.rb', line 19
def record_validation_context_for_association(record) record.custom_validation_context? ? record.validation_context : nil end
#valid_object?(record, context) ⇒ Boolean
(private)
# File 'activerecord/lib/active_record/validations/associated.rb', line 15
def valid_object?(record, context) (record.respond_to?(:marked_for_destruction?) && record.marked_for_destruction?) || record.valid?(context) end
#validate_each(record, attribute, value)
[ GitHub ]# File 'activerecord/lib/active_record/validations/associated.rb', line 6
def validate_each(record, attribute, value) context = record_validation_context_for_association(record) if Array(value).reject { |association| valid_object?(association, context) }.any? record.errors.add(attribute, :invalid, ** .merge(value: value)) end end