Created
May 15, 2011 22:41
-
-
Save toudi/973626 to your computer and use it in GitHub Desktop.
countWalkerPatch
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/library/DoctrineExtensions/Paginate/CountWalker.php b/library/DoctrineExtensions/Paginate/CountWalker.php | |
index 6512435..44456d8 100644 | |
--- a/library/DoctrineExtensions/Paginate/CountWalker.php | |
+++ b/library/DoctrineExtensions/Paginate/CountWalker.php | |
@@ -31,9 +31,14 @@ class CountWalker extends TreeWalkerAdapter | |
{ | |
$parent = null; | |
$parentName = null; | |
- | |
+ $removeAllGroupBy = false; | |
+ | |
foreach ($this->_getQueryComponents() AS $dqlAlias => $qComp) { | |
- | |
+ if (isset($qComp["resultVariable"]->functionName)) { | |
+ if ("count" == $qComp["resultVariable"]->functionName) { | |
+ $removeAllGroupBy = true; | |
+ } | |
+ } | |
// skip mixed data in query | |
if (isset($qComp['resultVariable'])) { | |
continue; | |
@@ -46,7 +51,6 @@ class CountWalker extends TreeWalkerAdapter | |
} | |
} | |
- | |
$pathExpression = new PathExpression( | |
PathExpression::TYPE_STATE_FIELD | PathExpression::TYPE_SINGLE_VALUED_ASSOCIATION, $parentName, | |
$parent['metadata']->getSingleIdentifierFieldName() | |
@@ -58,10 +62,12 @@ class CountWalker extends TreeWalkerAdapter | |
new AggregateExpression('count', $pathExpression, true), null | |
) | |
); | |
+ | |
// ORDER BY is not needed, only increases query execution through unnecessary sorting. | |
$AST->orderByClause = null; | |
// remove group by items that are not on the parent | |
+ if (!$removeAllGroupBy) { | |
foreach ($AST->groupByClause->groupByItems as $key => $item) { | |
if ($item->identificationVariable != $parentName) { | |
@@ -69,9 +75,10 @@ class CountWalker extends TreeWalkerAdapter | |
} | |
} | |
+ } | |
// if there are no items left then remove the group by | |
- if (count($AST->groupByClause->groupByItems) == 0) { | |
+ if (count($AST->groupByClause->groupByItems) == 0 || $removeAllGroupBy) { | |
$AST->groupByClause = null; | |
} | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/library/DoctrineExtensions/Paginate/LimitSubqueryWalker.php b/library/DoctrineExtensions/Paginate/LimitSubqueryWalker.php | |
index 65398e9..15e9794 100644 | |
--- a/library/DoctrineExtensions/Paginate/LimitSubqueryWalker.php | |
+++ b/library/DoctrineExtensions/Paginate/LimitSubqueryWalker.php | |
@@ -46,7 +46,7 @@ class LimitSubqueryWalker extends TreeWalkerAdapter | |
$parent = null; | |
$parentName = null; | |
foreach ($this->_getQueryComponents() AS $dqlAlias => $qComp) { | |
- if ($qComp['parent'] === null && $qComp['nestingLevel'] == 0) { | |
+ if (array_key_exists('parent', $qComp) && $qComp['parent'] === null && $qComp['nestingLevel'] == 0) { | |
$parent = $qComp; | |
$parentName = $dqlAlias; | |
break; | |
diff --git a/library/DoctrineExtensions/Paginate/WhereInWalker.php b/library/DoctrineExtensions/Paginate/WhereInWalker.php | |
index 6c6799a..0f85362 100644 | |
--- a/library/DoctrineExtensions/Paginate/WhereInWalker.php | |
+++ b/library/DoctrineExtensions/Paginate/WhereInWalker.php | |
@@ -55,7 +55,7 @@ class WhereInWalker extends TreeWalkerAdapter | |
$parent = null; | |
$parentName = null; | |
foreach ($this->_getQueryComponents() AS $dqlAlias => $qComp) { | |
- if ($qComp['parent'] === null && $qComp['nestingLevel'] == 0) { | |
+ if (array_key_exists('parent', $qComp) && $qComp['parent'] === null && $qComp['nestingLevel'] == 0) { | |
$parent = $qComp; | |
$parentName = $dqlAlias; | |
break; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment