Skip to content

Commit

Permalink
Add QueryBuilder::resetOrderBy() (doctrine#6190)
Browse files Browse the repository at this point in the history
  • Loading branch information
mbabker authored Oct 14, 2023
1 parent 02025a9 commit e8479d1
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/Query/QueryBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -1366,6 +1366,20 @@ public function resetQueryPart($queryPartName)
return $this;
}

/**
* Resets the ordering for the query.
*
* @return $this This QueryBuilder instance.
*/
public function resetOrderBy(): self
{
$this->sqlParts['orderBy'] = self::SQL_PARTS_DEFAULTS['orderBy'];

$this->state = self::STATE_DIRTY;

return $this;
}

/** @throws QueryException */
private function getSQLForSelect(): string
{
Expand Down
11 changes: 11 additions & 0 deletions tests/Query/QueryBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -631,6 +631,17 @@ public function testResetQueryParts(): void
self::assertEquals('SELECT u.* FROM users u', (string) $qb);
}

public function testResetOrderBy(): void
{
$qb = new QueryBuilder($this->conn);

$qb->select('u.*')->from('users', 'u')->orderBy('u.name');

self::assertEquals('SELECT u.* FROM users u ORDER BY u.name ASC', (string) $qb);
$qb->resetOrderBy();
self::assertEquals('SELECT u.* FROM users u', (string) $qb);
}

public function testCreateNamedParameter(): void
{
$qb = new QueryBuilder($this->conn);
Expand Down

0 comments on commit e8479d1

Please sign in to comment.