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
-
#includes(*relations) ⇒ Criteria
Eager loads all the provided relations.
-
#inclusions ⇒ Array<Metadata>
Get a list of criteria that are to be executed for eager loading.
-
#inclusions=(value) ⇒ Array<Metadata>
Set the inclusions for the criteria.
Instance Method Details
#includes(*relations) ⇒ Criteria
This will work for embedded relations that reference another collection via belongs_to as well.
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.
29 30 31 32 33 34 35 36 37 38 |
# File 'lib/mongoid/criteria/includable.rb', line 29 def includes(*relations) relations.flatten.each do |relation| if relation.is_a?(Hash) extract_nested_inclusion(klass, relation) else add_inclusion(klass, relation) end end clone end |
#inclusions ⇒ Array<Metadata>
Get a list of criteria that are to be executed for eager loading.
48 49 50 |
# File 'lib/mongoid/criteria/includable.rb', line 48 def inclusions @inclusions ||= [] end |
#inclusions=(value) ⇒ Array<Metadata>
Set the inclusions for the criteria.
62 63 64 |
# File 'lib/mongoid/criteria/includable.rb', line 62 def inclusions=(value) @inclusions = value end |