Skip to content

Commit

Permalink
Multiple joins (lookups) and unwinds in a query
Browse files Browse the repository at this point in the history
  • Loading branch information
TCB13 committed Oct 31, 2019
1 parent 246067a commit b5dd045
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/QueryBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,13 +120,13 @@ public function findAll(): self
$pipeline = [];
}

if (!empty($this->lookup)) // Lookups should ALWAYS be the first ones
{
$pipeline[] = $this->lookup;
// Lookups should ALWAYS be the first ones
if (!empty($this->lookup)) {
$pipeline = array_merge($pipeline, $this->lookup);
}

if (!empty($this->unwind)) {
$pipeline[] = $this->unwind;
$pipeline = array_merge($pipeline, $this->unwind);
}

if (!empty($this->addFields)) {
Expand Down Expand Up @@ -423,7 +423,7 @@ public function join($collection, $localField, $operatorOrForeignField, $foreign
]
];

$this->lookup = [
$this->lookup[] = [
"\$lookup" => [
"from" => key($collection),
"let" => [reset($foreignField) => "\$" . $localField],
Expand All @@ -432,7 +432,7 @@ public function join($collection, $localField, $operatorOrForeignField, $foreign
],
];

$this->unwind = [
$this->unwind[] = [
"\$unwind" => ["path" => "\$" . reset($collection)]
];

Expand Down

0 comments on commit b5dd045

Please sign in to comment.