Module: Mongoid::Criteria::Includable

Included in:
Mongoid::Criteria
Defined in:
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 associations 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 associations. 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 associations.

Person.includes(:posts, :game)

Parameters:

  • *relations ([ Symbol | Hash ]...)

    The names of the association(s) to eager load.

Returns:



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

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

#inclusionsArray<Mongoid::Association::Relatable>

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

Returns:



37
38
39
# File 'lib/mongoid/criteria/includable.rb', line 37

def inclusions
  @inclusions ||= []
end

#inclusions=(value) ⇒ Array<Mongoid::Association::Relatable>

Set the inclusions for the criteria.

Parameters:

Returns:



46
47
48
# File 'lib/mongoid/criteria/includable.rb', line 46

def inclusions=(value)
  @inclusions = value
end