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 query for selecting IDs for pagination #490

Gradius30 opened this issue May 14, 2018 · 3 comments


Copy link

commented May 14, 2018

There is a bug in query selecting IDs that are passed for query selecting paged items.

1st query = selecting count;
2nd query = selecting IDs that are selected in 3rd query ( using LIMIT ... OFFSET... )
3rd query = selecting items that are displayed

How to get to bug:

Lets say I have this query:


Entity\Gallery = media__gallery
Entity\Media = media__media
Entity\GalleryHasMedia = media__gallery_media

So basically what Im doing is selecting 'm' (Media) for displaying in paginated results.

The 2nd query thus should select not u0_id but so it can be used in 3rd query in WHERE statement.

2nd query

What it does now is instead of filling WHERE with (m1.)_Media IDs its using (u0.)_UserGallery IDs...

3rd query


This comment has been minimized.

Copy link

commented Sep 4, 2018

Can you post your complete code please (ie the multiple queries you're performing) ?
Also, please avoid to post screenshots, they're not easy to read. Please use markdown syntax highlighting instead.


This comment has been minimized.

Copy link

commented Sep 4, 2018

Hello. This is the DQL query:

FROM AppBundle:User\UserGallery ug 
INNER JOIN Application\Sonata\MediaBundle\Entity\Gallery g 
	WITH = 
INNER JOIN Application\Sonata\MediaBundle\Entity\GalleryHasMedia hm 
	WITH = 
INNER JOIN Application\Sonata\MediaBundle\Entity\Media m 
	WITH = 
WHERE ug.user = :user AND = :gallery 
ORDER BY m.sortablePosition DESC
$pagination = $paginator->paginate($qb, $request->query->getInt('p', 1), 5);

Paginator then generates query for selecting IDs (results to be displayed). Problem is it should select instead of

  DISTINCT AS id_0, 
  m1_.sortable_position AS sortable_position_1 
  user__galleries u0_ 
  INNER JOIN media__gallery m2_ ON ( = u0_.gallery_id) 
  AND (m2_.deleted_at IS NULL) 
  INNER JOIN media__gallery_media m3_ ON (m3_.gallery_id = 
  AND (m3_.deleted_at IS NULL) 
  INNER JOIN media__media m1_ ON ( = m3_.media_id) 
  AND (m1_.deleted_at IS NULL) 
    u0_.user_id = ? 
    AND u0_.gallery_id = ?
  AND (u0_.deleted_at IS NULL) 
  m1_.sortable_position DESC 
  5 OFFSET 0

So in short - paginator selects instead of As the is everywhere the same (which means same gallery ID) it basically displays all images of a gallery instead of only 5

@Gradius30 Gradius30 closed this Sep 4, 2018
@Gradius30 Gradius30 reopened this Sep 4, 2018

This comment has been minimized.

Copy link

commented Sep 5, 2018

Okay, it looks like the problem is more related to the query rather than to the paginator itself. Can you also explain the use case please ? What are you attempting to do ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
3 participants
You can’t perform that action at this time.