diff --git a/lib/Doctrine/ORM/Tools/Pagination/CountWalker.php b/lib/Doctrine/ORM/Tools/Pagination/CountWalker.php index 778dd3072..64914f5a6 100644 --- a/lib/Doctrine/ORM/Tools/Pagination/CountWalker.php +++ b/lib/Doctrine/ORM/Tools/Pagination/CountWalker.php @@ -57,7 +57,16 @@ class CountWalker extends TreeWalkerAdapter && $qComp['nestingLevel'] == 0 ; if ($isParent) { - $rootComponents[] = array($dqlAlias => $qComp); + foreach($AST->fromClause->identificationVariableDeclarations as $identificationVariableDeclaration) { + $isRoot = $identificationVariableDeclaration->rangeVariableDeclaration + && $identificationVariableDeclaration->rangeVariableDeclaration->aliasIdentificationVariable == $dqlAlias + && $identificationVariableDeclaration->rangeVariableDeclaration->isRoot + ; + if ($isRoot) { + $rootComponents[] = array($dqlAlias => $qComp); + break; + } + } } } if (count($rootComponents) > 1) { diff --git a/lib/Doctrine/ORM/Tools/Pagination/WhereInWalker.php b/lib/Doctrine/ORM/Tools/Pagination/WhereInWalker.php index 27cbc3c2e..460b8a708 100644 --- a/lib/Doctrine/ORM/Tools/Pagination/WhereInWalker.php +++ b/lib/Doctrine/ORM/Tools/Pagination/WhereInWalker.php @@ -78,7 +78,16 @@ class WhereInWalker extends TreeWalkerAdapter && $qComp['nestingLevel'] == 0 ; if ($isParent) { - $rootComponents[] = array($dqlAlias => $qComp); + foreach($AST->fromClause->identificationVariableDeclarations as $identificationVariableDeclaration) { + $isRoot = $identificationVariableDeclaration->rangeVariableDeclaration + && $identificationVariableDeclaration->rangeVariableDeclaration->aliasIdentificationVariable == $dqlAlias + && $identificationVariableDeclaration->rangeVariableDeclaration->isRoot + ; + if ($isRoot) { + $rootComponents[] = array($dqlAlias => $qComp); + break; + } + } } } if (count($rootComponents) > 1) {