Module: Mongoid::Validations::ClassMethods

Defined in:
lib/mongoid/validations.rb

Overview

:nodoc:

Instance Method Summary collapse

Instance Method Details

#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 (Array)

    The arguments to pass to the validator.



101
102
103
# File 'lib/mongoid/validations.rb', line 101

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

#validates_uniqueness_of(*args) ⇒ Object

Validates whether or not a field is unique against the documents in the database.

Examples:


class Person
  include Mongoid::Document
  field :title

  validates_uniqueness_of :title
end

Parameters:

  • *args (Array)

    The arguments to pass to the validator.



118
119
120
# File 'lib/mongoid/validations.rb', line 118

def validates_uniqueness_of(*args)
  validates_with(UniquenessValidator, _merge_attributes(args))
end