Class: Mongoid::Association::Eager
- Inherits:
-
Object
- Object
- Mongoid::Association::Eager
- Defined in:
- lib/mongoid/association/eager.rb
Overview
Base class for eager load preload functions.
Direct Known Subclasses
Mongoid::Association::Embedded::Eager, Referenced::BelongsTo::Eager, Referenced::HasAndBelongsToMany::Eager, Referenced::HasMany::Eager, Referenced::HasOne::Eager
Instance Method Summary collapse
-
#initialize(associations, docs) ⇒ Base
constructor
Instantiate the eager load class.
-
#run ⇒ Array
Run the preloader.
Constructor Details
#initialize(associations, docs) ⇒ Base
Instantiate the eager load class.
19 20 21 22 23 |
# File 'lib/mongoid/association/eager.rb', line 19 def initialize(associations, docs) @associations = associations @docs = docs @grouped_docs = {} end |
Instance Method Details
#run ⇒ Array
Run the preloader.
31 32 33 34 35 36 37 38 |
# File 'lib/mongoid/association/eager.rb', line 31 def run @loaded = [] while shift_association preload @loaded << @docs.collect { |d| d.send(@association.name) if d.respond_to?(@association.name) } end @loaded.flatten end |