Skip to content

Commit

Permalink
Merge pull request doctrine#10789 from macroparts/distinct-updates-st…
Browse files Browse the repository at this point in the history
…ate-correctly

distinct() updates QueryBuilder state correctly
  • Loading branch information
greg0ire authored Jun 25, 2023
2 parents f76bab2 + efb50b9 commit 4e13890
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lib/Doctrine/ORM/QueryBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -809,7 +809,12 @@ public function select($select = null)
*/
public function distinct($flag = true)
{
$this->dqlParts['distinct'] = (bool) $flag;
$flag = (bool) $flag;

if ($this->dqlParts['distinct'] !== $flag) {
$this->dqlParts['distinct'] = $flag;
$this->state = self::STATE_DIRTY;
}

return $this;
}
Expand Down
12 changes: 12 additions & 0 deletions tests/Doctrine/Tests/ORM/QueryBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1087,6 +1087,18 @@ public function testAddDistinct(): void
self::assertEquals('SELECT DISTINCT u FROM Doctrine\Tests\Models\CMS\CmsUser u', $qb->getDQL());
}

public function testDistinctUpdatesState(): void
{
$qb = $this->entityManager->createQueryBuilder()
->select('u')
->from(CmsUser::class, 'u');

$qb->getDQL();
$qb->distinct();

self::assertEquals('SELECT DISTINCT u FROM Doctrine\Tests\Models\CMS\CmsUser u', $qb->getDQL());
}

/** @group DDC-2192 */
public function testWhereAppend(): void
{
Expand Down

0 comments on commit 4e13890

Please sign in to comment.