I would like to paginate a complex request with at least 2 left joins, but the pagination bundle I\'m using (KnpPaginationBundle) can\'t tell Doctrine how to count the resul
For anyone looking for an answer about this, there is a good solution at: https://github.com/KnpLabs/KnpPaginatorBundle/blob/master/Resources/doc/manual_counting.md
$paginator = new Paginator;
// determine the count of the entire result set
$count = $entityManager
->createQuery('SELECT COUNT(c) FROM Entity\CompositeKey c')
->getSingleScalarResult();
// create a query to be used with the paginator, and specify a hint
$query = $entityManager
->createQuery('SELECT c FROM Entity\CompositeKey c')
->setHint(
'knp_paginator.count',
$count
);
// paginate, and set "disctinct" option to false
$pagination = $paginator->paginate(
$query,
1,
10,
array(
'distinct' => false,
)
);
Basically, what you are doing, is you are creating your own 'count' query and instruct knp paginator to use this.