From 114bd2435f301f84b84dd08866bdb8960c523d72 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Franti=C5=A1ek=20Bere=C5=88?= Date: Wed, 30 Jul 2014 09:56:22 +0200 Subject: [PATCH] Arbitrary Join count walkers solution Possible solution for Arbitrary Join problem in pagination count walkers: https://groups.google.com/forum/#!topic/doctrine-user/rpPYCDNKOU8 Added a condition to test query component against SelectStatement from clause --- lib/Doctrine/ORM/Tools/Pagination/CountWalker.php | 11 ++++++++++- lib/Doctrine/ORM/Tools/Pagination/WhereInWalker.php | 11 ++++++++++- 2 files changed, 20 insertions(+), 2 deletions(-) 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) {