lib/mongoid/validatable/uniqueness.rb
# Get the default criteria for checking uniqueness.
#
# @api private
#
# @example Get the criteria.
#   validator.criterion(person, :title, "Sir")
#
# @param [ Document ] document The document to validate.
# @param [ Symbol ] attribute The name of the attribute.
# @param [ Object ] value The value of the object.
#
# @return [ Criteria ] The uniqueness criteria.
Get the default criteria for checking uniqueness.
Get the default criteria for checking uniqueness .
def criterion(document, attribute, value)
        field = document.database_field_name(attribute)
        if value && localized?(document, field)
          conditions = (value || {}).inject([]) { |acc, (k,v)| acc << { "#{field}.#{k}" => filter(v) }}
          selector = { "$or" => conditions }
        else
          selector = { field => filter(value) }
        end
        if document.persisted? && !document.embedded?
          selector.merge!(_id: { "$ne" => document._id })
        end
        selector
      end
def criterion ( document , attribute , value ) field = document . database_field_name ( attribute ) if value && localized? ( document , field ) conditions = ( value || { } ) . inject ( [ ] ) { | acc , ( k , v ) | acc << { "#{field}.#{k}" => filter ( v ) } } selector = { "$or" => conditions } else selector = { field => filter ( value ) } end if document . persisted? && ! document . embedded? selector . merge! ( _id : { "$ne" => document . _id } ) end selector end
Get the default criteria for checking uniqueness.
Get the default criteria for checking uniqueness .
The uniqueness criteria.
The uniqueness criteria .
 Criteria 
document
<not_specific>
attribute
<not_specific>
value
<not_specific>
<not_specific>
value The value of the object.
value The value of the object .
api
None
example
Get the criteria. validator.criterion(person, :title, "Sir")
Get the criteria . validator . criterion ( person : title " Sir " )