Jeremy Hicks, thanks for your extension.
I didn`t know how to connect your function to doctrine, but finally i find answer.
$doctrineConfig = $this->em->getConfiguration();
$doctrineConfig->addCustomStringFunction('FIELD', 'DoctrineExtensionsQueryMysqlField');
I need FIELD
function to order my Entities that i select by IN
expression. But you can use this function only in SELECT, WHERE, BETWEEN
clause, not in ORDER BY
.
Solution:
$qb
->select("r, field(r.id, " . implode(", ", $ids) . ") as HIDDEN field")
->from("EntitiesRound", "r")
->where($qb->expr()->in("r.id", $ids))
->orderBy("field");
To avoid adding field
alias into your result row you need put HIDDEN
keyword. So this how to be able order values in IN
expression in Doctrine 2.2.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…