123456789_123456789_123456789_123456789_123456789_

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

.kind

Returns the kind of the validator.

.new

Accepts options that will be made available through the options reader.

Instance Attribute Summary

Instance Method Summary

::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 errors array where necessary.

#prepare_value_for_validation

::ActiveModel::Validator - Inherited

#kind

Returns the kind for this validator.

#validate

Override this method in subclasses with validation logic, adding errors to the records errors array where necessary.

Constructor Details

This class inherits a constructor from ActiveModel::EachValidator

Instance Method Details

#valid_object?(record) ⇒ Boolean (private)

[ GitHub ]

  
# File 'activerecord/lib/active_record/validations/associated.rb', line 13

def valid_object?(record)
  (record.respond_to?(:marked_for_destruction?) && record.marked_for_destruction?) || record.valid?
end

#validate_each(record, attribute, value)

[ GitHub ]

  
# File 'activerecord/lib/active_record/validations/associated.rb', line 6

def validate_each(record, attribute, value)
  if Array(value).reject { |r| valid_object?(r) }.any?
    record.errors.add(attribute, :invalid, **options.merge(value: value))
  end
end