Skip to content

Doctrine dbal groupby #284

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions src/Pagerfanta/Adapter/DoctrineDbalAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
*/
class DoctrineDbalAdapter implements AdapterInterface
{
private $queryBuilder;
private $countQueryBuilderModifier;
protected $queryBuilder;
protected $countQueryBuilderModifier;

/**
* Constructor.
Expand Down Expand Up @@ -54,12 +54,16 @@ public function getNbResults()
return (int) $result;
}

private function prepareCountQueryBuilder()
protected function prepareCountQueryBuilder()
{
$qb = clone $this->queryBuilder;
call_user_func($this->countQueryBuilderModifier, $qb);

return $qb;
// group by queries are problematic to get total row count
// we are able to create new QueryBuilder instance using old QueryBuilder as a subquery
// to get total row count
$retVal = call_user_func($this->countQueryBuilderModifier, $qb);

return !is_null($retVal) && ($retVal instanceof QueryBuilder) ? $retVal : $qb;
}

/**
Expand Down