Module: Mongoid::Criteria::Includable

Included in:
Mongoid::Criteria
Defined in:
build/mongoid-7.0/lib/mongoid/criteria/includable.rb

Overview

Module providing functionality for parsing (nested) inclusion definitions.

Instance Method Summary collapse

Instance Method Details

#includes(*relations) ⇒ Criteria

Note:

This will work for embedded relations that reference another collection via belongs_to as well.

Note:

Eager loading brings all the documents into memory, so there is a sweet spot on the performance gains. Internal benchmarks show that eager loading becomes slower around 100k documents, but this will naturally depend on the specific application.

Eager loads all the provided relations. Will load all the documents into the identity map whose ids match based on the extra query for the ids.

Examples:

Eager load the provided relations.

Person.includes(:posts, :game)

Parameters:

  • relations (Array<Symbol>, Array<Hash>)

    The names of the relations to eager load.

Returns:

Since:

  • 2.2.0



29
30
31
32
# File 'build/mongoid-7.0/lib/mongoid/criteria/includable.rb', line 29

def includes(*relations)
  extract_includes_list(klass, relations)
  clone
end

#inclusionsArray<Association>

Get a list of criteria that are to be executed for eager loading.

Examples:

Get the eager loading inclusions.

Person.includes(:game).inclusions

Returns:

Since:

  • 2.2.0



42
43
44
# File 'build/mongoid-7.0/lib/mongoid/criteria/includable.rb', line 42

def inclusions
  @inclusions ||= []
end

#inclusions=(value) ⇒ Array<Association>

Set the inclusions for the criteria.

Examples:

Set the inclusions.

criteria.inclusions = [ association ]

Parameters:

Returns:

Since:

  • 3.0.0



56
57
58
# File 'build/mongoid-7.0/lib/mongoid/criteria/includable.rb', line 56

def inclusions=(value)
  @inclusions = value
end