Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

[Paginator] Added support for order by scalar #559

Merged
merged 5 commits into from

6 participants

@f1nder

No description provided.

@doctrinebot
Collaborator

Hello,

thank you for positing this Pull Request. I have automatically opened an issue on our Jira Bug Tracker for you with the details of this Pull-Request. See the Link:

http://doctrine-project.org/jira/browse/DDC-2262

composer.json
@@ -6,27 +6,44 @@
"homepage": "http://www.doctrine-project.org",
@Ocramius Owner

Revert all these changes please

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
...RM/Tools/Pagination/LimitSubqueryOutputWalkerTest.php
@@ -25,7 +25,7 @@ public function testLimitSubqueryWithSortPg()
$this->entityManager->getConnection()->setDatabasePlatform(new \Doctrine\DBAL\Platforms\PostgreSqlPlatform);
$query = $this->entityManager->createQuery(
- 'SELECT p, c, a FROM Doctrine\Tests\ORM\Tools\Pagination\MyBlogPost p JOIN p.category c JOIN p.author a ORDER BY p.title');
+ 'SELECT p, C, a FROM Doctrine\Tests\ORM\Tools\Pagination\MyBlogPost p JOIN p.category C JOIN p.author a ORDER BY p.title');
@Ocramius Owner

Why was this one changed?

@f1nder
f1nder added a note

This is typo. Fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
...ne/ORM/Tools/Pagination/LimitSubqueryOutputWalker.php
((14 lines not shown))
$sqlOrderColumns[] = $alias;
- $orderBy[] = $alias . ' ' . $item->type;
+ $orderBy[] = $alias . ' ' . $item->type;
@stof
stof added a note

this should be reverted

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
...ne/ORM/Tools/Pagination/LimitSubqueryOutputWalker.php
@@ -179,12 +179,16 @@ public function getPostgresqlSql(SelectStatement $AST, array $sqlIdentifier, $in
$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)) {
@guilhermeblanco Owner

This should be re-written to:

$possibleAliases = (is_object($item->expression))
    ? array_keys($this->rsm->fieldMappings, $item->expression->field)
    : array_keys($this->rsm->scalarMappings, $item->expression);
@f1nder
f1nder added a note

done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@guilhermeblanco guilhermeblanco merged commit 3d1956d into doctrine:master
@f1nder f1nder deleted the f1nder:fix-paginator branch
@Majkl578

Any reason why isn't this backported to 2.3.x? I've just encountered this issue, which seems to be fixed for 5 months already. Sad.

Owner

@Majkl578 only bug fixes are backported

@Ocramius: Not supporting scalar is a bug, since DQL supports it natively.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jan 26, 2013
  1. Add test for order by scalar

    aleks authored
  2. Added support for order by scalar

    aleks authored
  3. Fix typo

    aleks authored
Commits on Jan 27, 2013
  1. Fix typo

    aleks authored
  2. Add test with mixed sort

    aleks authored
This page is out of date. Refresh to see the latest.
View
6 lib/Doctrine/ORM/Tools/Pagination/LimitSubqueryOutputWalker.php
@@ -179,10 +179,12 @@ public function getPostgresqlSql(SelectStatement $AST, array $sqlIdentifier, $in
$orderBy = array();
if (isset($AST->orderByClause)) {
foreach ($AST->orderByClause->orderByItems as $item) {
- $possibleAliases = array_keys($this->rsm->fieldMappings, $item->expression->field);
+ $possibleAliases = (is_object($item->expression))
+ ? array_keys($this->rsm->fieldMappings, $item->expression->field)
+ : 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;
break;
View
38 tests/Doctrine/Tests/ORM/Tools/Pagination/LimitSubqueryOutputWalkerTest.php
@@ -36,6 +36,44 @@ public function testLimitSubqueryWithSortPg()
$this->entityManager->getConnection()->setDatabasePlatform($odp);
}
+ public function testLimitSubqueryWithScalarSortPg()
+ {
+ $odp = $this->entityManager->getConnection()->getDatabasePlatform();
+ $this->entityManager->getConnection()->setDatabasePlatform(new \Doctrine\DBAL\Platforms\PostgreSqlPlatform);
+
+ $query = $this->entityManager->createQuery(
+ 'SELECT u, g, COUNT(g.id) AS g_quantity FROM Doctrine\Tests\ORM\Tools\Pagination\User u JOIN u.groups g ORDER BY g_quantity'
+ );
+ $limitQuery = clone $query;
+ $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",
+ $limitQuery->getSql()
+ );
+
+ $this->entityManager->getConnection()->setDatabasePlatform($odp);
+ }
+
+ public function testLimitSubqueryWithMixedSortPg()
+ {
+ $odp = $this->entityManager->getConnection()->getDatabasePlatform();
+ $this->entityManager->getConnection()->setDatabasePlatform(new \Doctrine\DBAL\Platforms\PostgreSqlPlatform);
+
+ $query = $this->entityManager->createQuery(
+ 'SELECT u, g, COUNT(g.id) AS g_quantity FROM Doctrine\Tests\ORM\Tools\Pagination\User u JOIN u.groups g ORDER BY g_quantity, u.id DESC'
+ );
+ $limitQuery = clone $query;
+ $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, u1_.id DESC) dctrn_result ORDER BY sclr0 ASC, id1 DESC",
+ $limitQuery->getSql()
+ );
+
+ $this->entityManager->getConnection()->setDatabasePlatform($odp);
+ }
+
public function testLimitSubqueryPg()
{
$odp = $this->entityManager->getConnection()->getDatabasePlatform();
Something went wrong with that request. Please try again.