I want to replicate the following query which sorts all users by name, but those whose names start with Z come first:
SELECT *
FROM user
ORDER BY LEFT(name, 1) != 'Z', name
I have this:
$qb = $this->getEntityManager()->createQueryBuilder();
$qb->select('u')
->addSelect($qb->expr()->neq($qb->expr()->substring('u.name', 1, 1), $qb->expr()->literal('Z')) . ' AS HIDDEN firstLetterIsNotZ')
->from(user::class, 'u')
->orderBy('firstLetterIsNotZ')
->addOrderBy('u.name');
The generated DQL looks sane enough:
SELECT s, SUBSTRING(u.name, 1, 1) <> 'Z' AS HIDDEN descriptionFirstLetter
FROM user u
ORDER BY firstLetterIsNotZASC, s.description ASC
But the lexer does not like it:
Error: Expected Doctrine\ORM\Query\Lexer::T_FROM, got '<'