Class Mongoid::Validations::AssociatedValidator
In: lib/mongoid/validations/associated.rb
Parent: ActiveModel::EachValidator

Validates whether or not an association is valid or not. Will correctly handle has one and has many associations.

@example Set up the association validations.

  class Person
    include Mongoid::Document
    embeds_one :name
    embeds_many :addresses

    validates_associated :name, :addresses
  end

Methods

Public Instance methods

Validates that the associations provided are either all nil or all valid. If neither is true then the appropriate errors will be added to the parent document.

@example Validate the association.

  validator.validate_each(document, :name, name)

@param [ Document ] document The document to validate. @param [ Symbol ] attribute The relation to validate. @param [ Object ] value The value of the relation.

[Validate]