Module: Mongoid::Contexts

Extended by:
Contexts
Included in:
Contexts
Defined in:
lib/mongoid/contexts/mongo.rb,
lib/mongoid/contexts.rb,
lib/mongoid/contexts/enumerable.rb,
lib/mongoid/contexts/enumerable/sort.rb

Overview

:nodoc:

Defined Under Namespace

Classes: Enumerable, Mongo

Instance Method Summary collapse

Instance Method Details

#context_for(criteria, embedded = false) ⇒ Enumerable, Mongo

Determines the context to be used for this criteria. If the class is an embedded document, then the context will be the array in the has_many association it is in. If the class is a root, then the database itself will be the context.

Examples:

Get the context for the criteria.

Contexts.context_for(criteria)

Parameters:

  • criteria (Criteria)

    The criteria to use.

  • embedded (true, false) (defaults to: false)

    Whether this is on embedded documents.

Returns:



21
22
23
# File 'lib/mongoid/contexts.rb', line 21

def context_for(criteria, embedded = false)
  embedded ? Enumerable.new(criteria) : Mongo.new(criteria)
end