Module: Mongoid::Validatable::Queryable Private

Included in:
UniquenessValidator
Defined in:
lib/mongoid/validatable/queryable.rb

Overview

This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.

TODO:

Move this into the Mongoid::Validatable::Uniqueness class.

Mixin module included in Mongoid::Validatable::Uniqueness class when ensures that the persistence context is cleared when executing uniqueness queries.

Instance Method Summary collapse

Instance Method Details

#with_query(document) ⇒ Object

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.

Wrap the validation inside the an execution block that alert’s the client not to clear its persistence options.

Examples:

Execute the validation with a query.

with_query(document) do
  #...
end

Parameters:

  • document (Document)

    The document being validated.

Returns:

  • (Object)

    The result of the yield.



27
28
29
30
31
32
33
34
35
# File 'lib/mongoid/validatable/queryable.rb', line 27

def with_query(document)
  klass = document.class
  begin
    Threaded.begin_execution("#{klass.name}-validate-with-query")
    yield
  ensure
    Threaded.exit_execution("#{klass.name}-validate-with-query")
  end
end