From 5e6bc0847fa1a2eb39750fe2727f1faa944189d8 Mon Sep 17 00:00:00 2001 From: aleks Date: Sat, 26 Jan 2013 21:31:45 +0200 Subject: [PATCH] Added support for order by scalar --- .../ORM/Tools/Pagination/LimitSubqueryOutputWalker.php | 10 +++++++--- .../Tools/Pagination/LimitSubqueryOutputWalkerTest.php | 2 +- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/lib/Doctrine/ORM/Tools/Pagination/LimitSubqueryOutputWalker.php b/lib/Doctrine/ORM/Tools/Pagination/LimitSubqueryOutputWalker.php index a0ccc982d..02eaeeaa5 100644 --- a/lib/Doctrine/ORM/Tools/Pagination/LimitSubqueryOutputWalker.php +++ b/lib/Doctrine/ORM/Tools/Pagination/LimitSubqueryOutputWalker.php @@ -179,12 +179,16 @@ class LimitSubqueryOutputWalker extends SqlWalker $orderBy = array(); if (isset($AST->orderByClause)) { foreach ($AST->orderByClause->orderByItems as $item) { - $possibleAliases = array_keys($this->rsm->fieldMappings, $item->expression->field); + if (is_object($item->expression)) { + $possibleAliases = array_keys($this->rsm->fieldMappings, $item->expression->field); + } else { + $possibleAliases = array_keys($this->rsm->scalarMappings, $item->expression); + } foreach ($possibleAliases as $alias) { - if ($this->rsm->columnOwnerMap[$alias] == $item->expression->identificationVariable) { + if (!is_object($item->expression) || $this->rsm->columnOwnerMap[$alias] == $item->expression->identificationVariable) { $sqlOrderColumns[] = $alias; - $orderBy[] = $alias . ' ' . $item->type; + $orderBy[] = $alias . ' ' . $item->type; break; } } diff --git a/tests/Doctrine/Tests/ORM/Tools/Pagination/LimitSubqueryOutputWalkerTest.php b/tests/Doctrine/Tests/ORM/Tools/Pagination/LimitSubqueryOutputWalkerTest.php index 7735f3cd6..2e8e8d042 100644 --- a/tests/Doctrine/Tests/ORM/Tools/Pagination/LimitSubqueryOutputWalkerTest.php +++ b/tests/Doctrine/Tests/ORM/Tools/Pagination/LimitSubqueryOutputWalkerTest.php @@ -48,7 +48,7 @@ class LimitSubqueryOutputWalkerTest extends PaginationTestCase $limitQuery->setHint(Query::HINT_CUSTOM_OUTPUT_WALKER, 'Doctrine\ORM\Tools\Pagination\LimitSubqueryOutputWalker'); $this->assertEquals( - "SELECT DISTINCT id1, sclr0 FROM (SELECT COUNT(g0_.id) AS sclr0, u1_.id AS id1, g0_.id AS id2 FROM USER u1_ INNER JOIN user_group u2_ ON u1_.id = u2_.user_id INNER JOIN groups g0_ ON g0_.id = u2_.group_id ORDER BY sclr0 ASC) dctrn_result ORDER BY sclr0 ASC", + "SELECT DISTINCT id1, sclr0 FROM (SELECT COUNT(g0_.id) AS sclr0, u1_.id AS id1, g0_.id AS id2 FROM User u1_ INNER JOIN user_group u2_ ON u1_.id = u2_.user_id INNER JOIN groups g0_ ON g0_.id = u2_.group_id ORDER BY sclr0 ASC) dctrn_result ORDER BY sclr0 ASC", $limitQuery->getSql() );