Pagerfanta icon indicating copy to clipboard operation
Pagerfanta copied to clipboard

Aliased select subquery cannot by used in orderBy

Open juuga opened this issue 10 years ago • 3 comments

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''

juuga avatar Apr 29 '14 12:04 juuga

Please give the stack trace of the exception so that we know where this exception happens

stof avatar Apr 29 '14 12:04 stof

This appears to be a bug in Doctrine, not Pagerfanta.

https://github.com/doctrine/doctrine2/issues/4510

harmstyler avatar Oct 24 '16 20:10 harmstyler

Ran into this issue today - does any of you know a fix/workaround to this?

mrbase avatar May 03 '17 12:05 mrbase