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
Referenced::BelongsTo::Eager, Referenced::HasAndBelongsToMany::Eager, Referenced::HasMany::Eager, Referenced::HasOne::Eager
Instance Method Summary collapse
-
#initialize(associations, docs, use_lookup = false, pipeline = []) ⇒ Base
constructor
Instantiate the eager load class.
-
#run ⇒ Array
Run the preloader.
Constructor Details
#initialize(associations, docs, use_lookup = false, pipeline = []) ⇒ Base
Instantiate the eager load class.
21 22 23 24 25 26 27 |
# File 'lib/mongoid/association/eager.rb', line 21 def initialize(associations, docs, use_lookup = false, pipeline = []) @associations = associations @docs = docs @grouped_docs = {} @use_lookup = use_lookup @pipeline = pipeline end |
Instance Method Details
#run ⇒ Array
Run the preloader.
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/mongoid/association/eager.rb', line 35 def run @loaded = [] if @use_lookup preload_with_lookup @loaded = @docs return @loaded.flatten end while shift_association preload @loaded << @docs.collect { |d| d.send(@association.name) if d.respond_to?(@association.name) } end @loaded.flatten end |