Class: Mongoid::Association::EagerLoad::JoinedInclusion Private
| Relationships & Source Files | |
| Super Chains via Extension / Inclusion / Inheritance | |
|
Class Chain:
self,
AssociationInclusion,
Inclusion
|
|
|
Instance Chain:
self,
AssociationInclusion,
Inclusion
|
|
| Inherits: |
Mongoid::Association::EagerLoad::AssociationInclusion
|
| Defined in: | lib/mongoid/association/eager_load/inclusion.rb |
Overview
A referenced inclusion: contributes a $lookup whose sub-pipeline holds its own children. When it lives inside an embedded document (a non-empty chain), the $lookup is distributed onto that embedded path instead of standing at the top level.
For a has_many :albums it contributes:
{ '$lookup' => {
'from' => 'albums',
'localField' => '_id', # the band's _id...
'foreignField' => 'band_id', # ...matched against each album's band_id
'as' => 'albums', # matches are written to this field
'pipeline' => [
{ '$sort' => {
'_id' => 1
} },
<children>
]
} }
Class Method Summary
-
.for?(association) ⇒ true | false
Internal use only
The default kind: a referenced, non-polymorphic association, i.e.
AssociationInclusion - Inherited
Instance Attribute Summary
AssociationInclusion - Inherited
Instance Method Summary
-
#contribute(destination, chain)
Internal use only
Append the $lookup, with the children in its sub-pipeline, to the destination; or distribute it onto the embedded path when nested in one.
Inclusion - Inherited
| #contribute | Add this inclusion's stages to the destination. |
Constructor Details
This class inherits a constructor from Mongoid::Association::EagerLoad::AssociationInclusion
Class Method Details
.for?(association) ⇒ true | false
The default kind: a referenced, non-polymorphic association, i.e. the one no sibling kind claims.
# File 'lib/mongoid/association/eager_load/inclusion.rb', line 94
def for?(association) (superclass.subclasses - [ self ]).none? { |kind| kind.for?(association) } end
Instance Method Details
#contribute(destination, chain)
Append the $lookup, with the children in its sub-pipeline, to the destination; or distribute it onto the embedded path when nested in one.
# File 'lib/mongoid/association/eager_load/inclusion.rb', line 106
def contribute(destination, chain) stage = @pipeline.lookup_stage_for(@association) @children.each { |child| child.contribute(stage['$lookup']['pipeline'], []) } if chain.empty? destination << stage else destination.concat(@pipeline.distribute(@association, chain, stage)) end end