Method: Mongoid::Validatable::Macros#validates_associated

Defined in:
lib/mongoid/validatable/macros.rb

#validates_associated(*args) ⇒ Object

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

Examples:


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

  validates_associated :name, :addresses
end

Parameters:

  • *args (Object...)

    The arguments to pass to the validator.



27
28
29
# File 'lib/mongoid/validatable/macros.rb', line 27

def validates_associated(*args)
  validates_with(AssociatedValidator, _merge_attributes(args))
end