Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Aliased select subquery cannot by used in orderBy #131

Open
juuga opened this issue Apr 29, 2014 · 3 comments
Open

Aliased select subquery cannot by used in orderBy #131

juuga opened this issue Apr 29, 2014 · 3 comments

Comments

@juuga
Copy link

juuga commented Apr 29, 2014

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''
@stof
Copy link
Contributor

stof commented Apr 29, 2014

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

@pablodip pablodip reopened this May 16, 2014
@harmstyler
Copy link

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

doctrine/orm#4510

@mrbase
Copy link

mrbase commented May 3, 2017

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

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants