1
0
mirror of synced 2025-02-02 21:41:45 +03:00

Test that orderByItem is string

This commit is contained in:
Pierre-Louis FORT 2017-11-10 10:45:57 +01:00
parent 91408a3a54
commit 4ab9413675
2 changed files with 16 additions and 1 deletions

View File

@ -95,7 +95,7 @@ class LimitSubqueryWalker extends TreeWalkerAdapter
if (isset($AST->orderByClause)) {
foreach ($AST->orderByClause->orderByItems as $item) {
if ( ! $item->expression instanceof PathExpression) {
if(isset($queryComponents[$item->expression])) {
if(is_string($item->expression) && isset($queryComponents[$item->expression])) {
$qComp = $queryComponents[$item->expression];
if (isset($qComp['resultVariable'])) {
$AST->selectClause->selectExpressions[] = new SelectExpression($qComp['resultVariable'], $item->expression);

View File

@ -38,6 +38,21 @@ class LimitSubqueryWalkerTest extends PaginationTestCase
);
}
public function testLimitSubqueryWithSortFunction()
{
$dql = 'SELECT p FROM Doctrine\Tests\ORM\Tools\Pagination\MyBlogPost p JOIN p.category c GROUP BY p.id ORDER BY COUNT(c.id)';
$query = $this->entityManager->createQuery($dql);
$limitQuery = clone $query;
$limitQuery->setHint(Query::HINT_CUSTOM_TREE_WALKERS, [LimitSubqueryWalker::class]);
$this->assertEquals(
"SELECT DISTINCT m0_.id AS id_0 FROM MyBlogPost m0_ INNER JOIN Category c1_ ON m0_.category_id = c1_.id GROUP BY m0_.id ORDER BY COUNT(c1_.id) ASC",
$limitQuery->getSQL()
);
}
public function testCountQuery_MixedResultsWithName()
{
$dql = 'SELECT a, sum(a.name) as foo FROM Doctrine\Tests\ORM\Tools\Pagination\Author a';