Class: Mongoid::Validatable::UniquenessValidator
- Inherits:
-
ActiveModel::EachValidator
- Object
- ActiveModel::EachValidator
- Mongoid::Validatable::UniquenessValidator
- Defined in:
- lib/mongoid/core_ext/validatable/uniqueness.rb
Overview
Validates whether or not a field is unique against the documents in the database.
Instance Method Summary collapse
-
#scope(criteria, document, _attribute) ⇒ Criteria
private
Scope the criteria to the scope options provided.
Instance Method Details
#scope(criteria, document, _attribute) ⇒ Criteria
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Scope the criteria to the scope options provided.
29 30 31 32 33 34 35 36 |
# File 'lib/mongoid/core_ext/validatable/uniqueness.rb', line 29 def scope(criteria, document, _attribute) Array.wrap([:scope]).each do |item| name = document.database_field_name(item) criteria = criteria.where(item => document.attributes[name]) end criteria = criteria.where(deleted_at: nil) if document.paranoid? criteria end |