Module: Mongoid::Association::EagerLoadable
- Included in:
- Contextual::Memory, Contextual::Mongo
- Defined in:
- lib/mongoid/association/eager_loadable.rb
Overview
This module defines the eager loading behavior for criteria.
Instance Method Summary collapse
Instance Method Details
#eager_load(docs) ⇒ Object
16 17 18 19 20 21 22 |
# File 'lib/mongoid/association/eager_loadable.rb', line 16 def eager_load(docs) docs.tap do |d| if eager_loadable? preload(criteria.inclusions, d) end end end |
#eager_loadable? ⇒ Boolean
12 13 14 |
# File 'lib/mongoid/association/eager_loadable.rb', line 12 def eager_loadable? !criteria.inclusions.empty? end |
#preload(relations, docs) ⇒ Object
24 25 26 27 28 29 30 31 32 33 |
# File 'lib/mongoid/association/eager_loadable.rb', line 24 def preload(relations, docs) relations.group_by(&:inverse_class_name) .values .each do |associations| associations.group_by(&:relation) .each do |relation, association| relation.eager_loader(association, docs).run end end end |