Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

52 lines (47 sloc) 1.404 kB
# encoding: utf-8
require "mongoid/validations/associated"
require "mongoid/validations/uniqueness"
I18n.load_path << File.join(
File.dirname(__FILE__), "validations", "locale", "en.yml"
)
module Mongoid #:nodoc:
# This module provides additional validations that ActiveModel does not
# provide: validates_associated and validates_uniqueness_of
module Validations
extend ActiveSupport::Concern
included do
include ActiveModel::Validations
end
module ClassMethods #:nodoc:
# Validates whether or not an association is valid or not. Will correctly
# handle has one and has many associations.
#
# Example:
#
# class Person
# include Mongoid::Document
# embeds_one :name
# embeds_many :addresses
#
# validates_associated :name, :addresses
# end
def validates_associated(*args)
validates_with(AssociatedValidator, _merge_attributes(args))
end
# Validates whether or not a field is unique against the documents in the
# database.
#
# Example:
#
# class Person
# include Mongoid::Document
# field :title
#
# validates_uniqueness_of :title
# end
def validates_uniqueness_of(*args)
validates_with(UniquenessValidator, _merge_attributes(args))
end
end
end
end
Jump to Line
Something went wrong with that request. Please try again.