Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.Sign up
Count goes haywire when sorting translatable fields. #307
If I order a paginator on a translatable field (done with ORMBehaviors\Translatable\Translation found on knplabs/doctrine-behaviors ), the totals are incorrect.
I have 16 items and 10 items per page, but this is what it says:
Page 1: 1 - 8 from 16
Where I expect this:
Page 1: 1 - 10 from 16
It works properly when sorting on a non-translatable field.
Could this have something to do with https://github.com/KnpLabs/KnpPaginatorBundle/blob/HEAD/Resources/doc/manual_counting.md ? If so, can't the count be done like this in the bundle:
or a subquery so all joins, group by's etc stay intact?
I can't seem to reproduce this anymore. Currently using this set of bundles:
Maybe they've fixed something.
@aderuwe can you reproduce this? Before I could test it though, I got this error when sorting:
It can be fixed by wrapping the queries in the paginator for count and distinct which, in my opinion, should be default behavior:
$paginator = $this->get('knp_paginator'); $pagination = $paginator->paginate( $items, $this->request->query->get('page', 1), $items_per_page, array( // To avoid problems with joins when doing a count or distinct, // wrap the queries in a subselect, see https://github.com/KnpLabs/KnpPaginatorBundle/issues/106#issuecomment-66918012 'wrap-queries'=>true ) );
See #106 (comment)