Class: Mongoid::Association::Referenced::Eager::Base
- Inherits:
-
Object
- Object
- Mongoid::Association::Referenced::Eager::Base
- Defined in:
- build/mongoid-7.3/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.
25 26 27 28 29 |
# File 'build/mongoid-7.3/lib/mongoid/association/referenced/eager.rb', line 25 def initialize(associations, docs) @associations = associations @docs = docs @grouped_docs = {} end |
Instance Method Details
#run ⇒ Array
Run the preloader.
39 40 41 42 43 44 45 46 |
# File 'build/mongoid-7.3/lib/mongoid/association/referenced/eager.rb', line 39 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 |