Module: Mongoid::Validatable::Queryable

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

Instance Method Summary collapse

Instance Method Details

#with_query(document) ⇒ Object

Wrap the validation inside the an execution block that alert’s the session 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.

Since:

  • 3.0.2



19
20
21
22
23
24
25
26
27
# File 'lib/mongoid/validatable/queryable.rb', line 19

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