Class: MongoModel::Validations::AssociatedValidator

Inherits:
ActiveModel::EachValidator
  • Object
show all
Defined in:
lib/mongomodel/concerns/validations/associated.rb

Instance Method Summary collapse

Instance Method Details

#validate_each(record, attribute, value) ⇒ Object


4
5
6
7
# File 'lib/mongomodel/concerns/validations/associated.rb', line 4

def validate_each(record, attribute, value)
  return if Array(value).map { |r| r.nil? || r.valid?(record.validation_context) }.all?
  record.errors.add(attribute, :invalid, options.merge(:value => value))
end