Within Entity Repository:
$qb = $this->createQueryBuilder('c');
//....
$qb->addSelect('POWER('.$qb->expr()->abs(
$qb->expr()->diff('c.latitude', $filter['latitude'])
).',2) AS ddst';
//....
return $qb->getQuery(); //to Pagerfanta with DoctrineORMAdapter
Errors:
QueryException: [Syntax Error] line 0, col 11: Error: Expected known function, got 'POWER'
QueryException: SELECT c, (POWER(ABS(c.delivery_latitude - 47.227163),2) AS ddst
FROM MyEntity c ORDER BY ddst ASC, c.created_at DESC (this is dql error)
What’s not right? Dql doesn’t support POWER. I didn’t found it in qb-expressions.
And… Maybe it will be helpfull for someone. Answer:
src/Acme/MyBundle/DQL/PowerFunction.php:
And using (in MyEntityRepository):
done.