Pagerfanta
Pagerfanta copied to clipboard
Aliased select subquery cannot by used in orderBy
My query builder looks like this:
$queryBuilder = new QueryBuilder($db);
$queryBuilder
->select('i.*', 'u.name', '(SELECT count(v.id) FROM my_vote v WHERE v.image_id = i.id) AS votes')
->from('my_image', 'i')
->leftJoin('i', 'my_user', 'u', 'i.user_id = u.id')
;
I want to order by the number of votes so I add
$queryBuilder->orderBy('votes', 'DESC');
With a statement object and fetchAll this works fine, but when given to pagerfanta, the column is not found and a PDO exception is thrown
Uncaught exception 'PDOException' with message 'SQLSTATE[42S22]: Column not found: 1054 Unknown column 'votes' in 'order clause''
Please give the stack trace of the exception so that we know where this exception happens
This appears to be a bug in Doctrine, not Pagerfanta.
https://github.com/doctrine/doctrine2/issues/4510
Ran into this issue today - does any of you know a fix/workaround to this?