Skip to content

Loading…

[DDC-2599] OrderBy #749

Closed
wants to merge 3 commits into from

4 participants

@samvdb

No description provided.

@doctrinebot

Hello,

thank you for creating this pull request. I have automatically opened an issue
on our Jira Bug Tracker for you. See the issue link:

http://www.doctrine-project.org/jira/browse/DDC-2600

We use Jira to track the state of pull requests and the versions they got
included in.

@Ocramius
Doctrine member

@samvdb can you please add a test that verifies the generated DQL?

@samvdb samvdb closed this
@guilhermeblanco
Doctrine member

@samvdb any reason to close this?
The failing test is due to a DQL parser issue, which can be easily fixed.

@samvdb

@guilhermeblanco, i was wrong to think index 0 or '0' is valid SQL. Index 1 or '1' on the other hand is valid in pgsql but doctrine doesnt accept this either. Im guessing this is not supported by all engines. Im no sql guru :)
A small bug might exist though when adding the following:

$qb->orderBy(0, 'DESC'); // outputs ORDER BY
Which is not correct because it's missing an expression.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Aug 7, 2013
  1. @samvdb

    fix for DDC-2599

    samvdb committed
  2. @samvdb

    fix for DDC-2599

    samvdb committed
  3. @samvdb
View
2 lib/Doctrine/ORM/Query/Expr/OrderBy.php
@@ -61,7 +61,7 @@ class OrderBy
*/
public function __construct($sort = null, $order = null)
{
- if ($sort) {
+ if ($sort !== null) {
$this->add($sort, $order);
}
}
View
4 tests/Doctrine/Tests/ORM/Query/ExprTest.php
@@ -405,6 +405,10 @@ public function testExpressionGetter()
// OrderBy
$order = new Expr\OrderBy('foo', 'DESC');
$this->assertEquals(array('foo DESC'), $order->getParts());
+ $order = new Expr\OrderBy('0', 'DESC');
+ $this->assertEquals(array('0 DESC'), $order->getParts());
+ $order = new Expr\OrderBy(0, 'DESC');
+ $this->assertEquals(array('0 DESC'), $order->getParts());
// Andx
$orx = new Expr\Orx(array('foo = 1', 'bar = 2'));
View
12 tests/Doctrine/Tests/ORM/Query/SelectSqlGenerationTest.php
@@ -1866,6 +1866,18 @@ public function testCaseThenParameterArithmeticExpression()
'SELECT SUM(CASE WHEN c0_.salary <= ? THEN c0_.salary - ? WHEN c0_.salary >= ? THEN ? - c0_.salary ELSE c0_.salary + ? END) AS sclr0 FROM company_employees c0_ INNER JOIN company_persons c1_ ON c0_.id = c1_.id'
);
}
+
+ /**
+ * @group DDC-2599
+ *
+ */
+ public function testSupportsOrderByColumnIndex()
+ {
+ $this->assertSqlGeneration(
+ 'SELECT u FROM Doctrine\Tests\Models\Forum\ForumUser u ORDER BY 0 asc',
+ 'SELECT f0_.id AS id0, f0_.username AS username1 FROM forum_users f0_ ORDER BY 0 ASC'
+ );
+ }
}
class MyAbsFunction extends \Doctrine\ORM\Query\AST\Functions\FunctionNode
Something went wrong with that request. Please try again.