Class: Mongoid::Association::EagerLoad::JoinedInclusion Private
- Inherits:
-
AssociationInclusion
- Object
- Inclusion
- AssociationInclusion
- Mongoid::Association::EagerLoad::JoinedInclusion
- Defined in:
- lib/mongoid/association/eager_load/inclusion.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
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>
]
} }
Instance Attribute Summary
Attributes inherited from AssociationInclusion
Class Method Summary collapse
-
.for?(association) ⇒ true | false
private
The default kind: a referenced, non-polymorphic association, i.e.
Instance Method Summary collapse
-
#contribute(destination, chain) ⇒ Object
private
Append the $lookup, with the children in its sub-pipeline, to the destination; or distribute it onto the embedded path when nested in one.
Methods inherited from AssociationInclusion
Constructor Details
This class inherits a constructor from Mongoid::Association::EagerLoad::AssociationInclusion
Class Method Details
.for?(association) ⇒ true | false
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
The default kind: a referenced, non-polymorphic association, i.e. the one no sibling kind claims.
94 95 96 |
# 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) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Append the $lookup, with the children in its sub-pipeline, to the destination; or distribute it onto the embedded path when nested in one.
106 107 108 109 110 111 112 113 114 115 |
# 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 |