diff --git a/lib/Doctrine/ODM/MongoDB/Aggregation/Stage/Fill.php b/lib/Doctrine/ODM/MongoDB/Aggregation/Stage/Fill.php index 4fc564f64..39a1fc4b4 100644 --- a/lib/Doctrine/ODM/MongoDB/Aggregation/Stage/Fill.php +++ b/lib/Doctrine/ODM/MongoDB/Aggregation/Stage/Fill.php @@ -86,7 +86,9 @@ public function getExpression(): array $params = (object) []; if ($this->partitionBy) { - $params->partitionBy = $this->partitionBy; + $params->partitionBy = $this->partitionBy instanceof Expr + ? $this->partitionBy->getExpression() + : $this->partitionBy; } if ($this->partitionByFields) { diff --git a/tests/Doctrine/ODM/MongoDB/Tests/Aggregation/Stage/FillTest.php b/tests/Doctrine/ODM/MongoDB/Tests/Aggregation/Stage/FillTest.php index 7bab5a7ed..e83b187a6 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/Aggregation/Stage/FillTest.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/Aggregation/Stage/FillTest.php @@ -44,6 +44,30 @@ public function testStage(): void ); } + public function testStageWithExpressionAsPartition(): void + { + $builder = $this->getTestAggregationBuilder(); + $fillStage = new Fill($builder); + $fillStage + ->partitionBy($builder->expr()->year('$field')) + ->sortBy('field1', 1) + ->output() + ->field('foo')->locf(); + + self::assertEquals( + [ + '$fill' => (object) [ + 'partitionBy' => ['$year' => '$field'], + 'sortBy' => (object) ['field1' => 1], + 'output' => (object) [ + 'foo' => ['method' => 'locf'], + ], + ], + ], + $fillStage->getExpression(), + ); + } + public function testStageWithComplexSort(): void { $fillStage = new Fill($this->getTestAggregationBuilder());