Class: Mongoid::Association::Referenced::Eager::Base
- Inherits:
-
Object
- Object
- Mongoid::Association::Referenced::Eager::Base
- Defined in:
- lib/mongoid/association/referenced/eager.rb
Overview
Base class for eager load preload functions.
Direct Known Subclasses
BelongsTo::Eager, HasAndBelongsToMany::Eager, HasMany::Eager, 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.
23 24 25 26 27 |
# File 'lib/mongoid/association/referenced/eager.rb', line 23 def initialize(associations, docs) @associations = associations @docs = docs @grouped_docs = {} end |
Instance Method Details
#run ⇒ Array
Run the preloader.
37 38 39 40 41 42 43 44 |
# File 'lib/mongoid/association/referenced/eager.rb', line 37 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 |