Skip to content

Commit b5dd045

Browse files
committed
Multiple joins (lookups) and unwinds in a query
1 parent 246067a commit b5dd045

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

src/QueryBuilder.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -120,13 +120,13 @@ public function findAll(): self
120120
$pipeline = [];
121121
}
122122

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

128128
if (!empty($this->unwind)) {
129-
$pipeline[] = $this->unwind;
129+
$pipeline = array_merge($pipeline, $this->unwind);
130130
}
131131

132132
if (!empty($this->addFields)) {
@@ -423,7 +423,7 @@ public function join($collection, $localField, $operatorOrForeignField, $foreign
423423
]
424424
];
425425

426-
$this->lookup = [
426+
$this->lookup[] = [
427427
"\$lookup" => [
428428
"from" => key($collection),
429429
"let" => [reset($foreignField) => "\$" . $localField],
@@ -432,7 +432,7 @@ public function join($collection, $localField, $operatorOrForeignField, $foreign
432432
],
433433
];
434434

435-
$this->unwind = [
435+
$this->unwind[] = [
436436
"\$unwind" => ["path" => "\$" . reset($collection)]
437437
];
438438

0 commit comments

Comments
 (0)