Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Wrong results with groupBy, DoctrineORMAdapter, useOutPutWalkers must be true #220

Closed
evesinger opened this issue Jan 31, 2017 · 2 comments

Comments

@evesinger
Copy link

Hello, I have a query that includes a group by and create the paginator with DoctrineORM like this:
$paginator = new Pagerfanta(new DoctrineORMAdapter($queryBuilder, true, false));
My expected count of results is 1 in this case and if I go to the queryBuilder and call getQuery->getResult it gives me the expected one. However, paginator->getNbResults() returns me 2.
Now, if I change the option "useOutPutWalkers" to true, ie. like this:
new Pagerfanta(new DoctrineORMAdapter($queryBuilder, true, true));, "count()" (or getNbResults()) returns the expected 1. I would like to know why this is, if it's a known issue or if it's expected behaviour. Any hints are welcome. Thanks very much.

@stof
Copy link
Contributor

stof commented Jan 31, 2017

This is logical. Some cases simply cannot return the right result when forbidding Doctrine to use output walkers. And GROUP BY is such a case as putting the COUNT directly in the select would return the count in each group, not the number of groups.

If you don't understand how the Doctrine ORM Paginator class works, the best is to avoid configuring it explicitly. The default value for useOutPutWalkers is null, which lets Doctrine guess the strategy it will use.
And while the selected strategy may not be the most efficient for all queries as it will tend to use the output walker more often than strictly necessary, it is meant to give you the right result.

@evesinger
Copy link
Author

thanks for clarifying. Much appreciated.

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

No branches or pull requests

2 participants