[DDC-2019] Add support for expression in QueryBuilder#addOrderBy()
This commit is contained in:
parent
9bf501dd25
commit
1a163cd48d
@ -1047,7 +1047,7 @@ class QueryBuilder
|
|||||||
* Specifies an ordering for the query results.
|
* Specifies an ordering for the query results.
|
||||||
* Replaces any previously specified orderings, if any.
|
* Replaces any previously specified orderings, if any.
|
||||||
*
|
*
|
||||||
* @param string $sort The ordering expression.
|
* @param string|Expr\OrderBy $sort The ordering expression.
|
||||||
* @param string $order The ordering direction.
|
* @param string $order The ordering direction.
|
||||||
*
|
*
|
||||||
* @return QueryBuilder This QueryBuilder instance.
|
* @return QueryBuilder This QueryBuilder instance.
|
||||||
@ -1062,14 +1062,16 @@ class QueryBuilder
|
|||||||
/**
|
/**
|
||||||
* Adds an ordering to the query results.
|
* Adds an ordering to the query results.
|
||||||
*
|
*
|
||||||
* @param string $sort The ordering expression.
|
* @param string|Expr\OrderBy $sort The ordering expression.
|
||||||
* @param string $order The ordering direction.
|
* @param string $order The ordering direction.
|
||||||
*
|
*
|
||||||
* @return QueryBuilder This QueryBuilder instance.
|
* @return QueryBuilder This QueryBuilder instance.
|
||||||
*/
|
*/
|
||||||
public function addOrderBy($sort, $order = null)
|
public function addOrderBy($sort, $order = null)
|
||||||
{
|
{
|
||||||
return $this->add('orderBy', new Expr\OrderBy($sort, $order), true);
|
$orderBy = ($sort instanceof Expr\OrderBy) ? $sort : new Expr\OrderBy($sort, $order);
|
||||||
|
|
||||||
|
return $this->add('orderBy', $orderBy, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -375,6 +375,17 @@ class QueryBuilderTest extends \Doctrine\Tests\OrmTestCase
|
|||||||
$this->assertValidQueryBuilder($qb, 'SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u ORDER BY u.username ASC, u.username DESC');
|
$this->assertValidQueryBuilder($qb, 'SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u ORDER BY u.username ASC, u.username DESC');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testAddOrderByWithExpression()
|
||||||
|
{
|
||||||
|
$qb = $this->_em->createQueryBuilder();
|
||||||
|
$qb->select('u')
|
||||||
|
->from('Doctrine\Tests\Models\CMS\CmsUser', 'u')
|
||||||
|
->orderBy('u.username', 'ASC')
|
||||||
|
->addOrderBy($qb->expr()->desc('u.username'));
|
||||||
|
|
||||||
|
$this->assertValidQueryBuilder($qb, 'SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u ORDER BY u.username ASC, u.username DESC');
|
||||||
|
}
|
||||||
|
|
||||||
public function testAddCriteriaWhere()
|
public function testAddCriteriaWhere()
|
||||||
{
|
{
|
||||||
$qb = $this->_em->createQueryBuilder();
|
$qb = $this->_em->createQueryBuilder();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user