Doctrine: Select statement using equals not accepted
Asked Answered
L

2

11

According to DDC-2204 issue which states

[Order by With Equals] is supported by including the condition in the SELECT clause, aliasing it, then using it. You might need to use "AS HIDDEN name" to prevent it from appearing in the result

following DQL should be possible:

SELECT main.id = 1 AS test FROM Entity main ORDER BY test

However, when I try this (using 2.4), I get

Error: Expected Doctrine\ORM\Query\Lexer::T_FROM, got '='

It seems the developer-advised method of putting the condition into SELECT does not work. Is this a bug and / or is there another way of selecting and / or ordering by condition.

Lavin answered 10/9, 2014 at 9:35 Comment(1)
I found: #15258038Tuneberg
P
4

It is possible to use case statement:

SELECT (CASE WHEN main.id = 1 THEN 1 ELSE 0 END) AS test FROM Entity main ORDER BY test

Poss answered 20/8, 2015 at 8:57 Comment(0)
W
0

I'm not sure, if I understand that article correctly, but it seems to refer to using the condition in the order by clause:

SELECT main.id AS test FROM Entity main ORDER BY test = 1
Wilk answered 10/9, 2014 at 12:17 Comment(1)
... which doesn't work in Doctrine and the proposed solution - putting it in SELECT clause - does not either, apparently.Lavin

© 2022 - 2024 — McMap. All rights reserved.