Преглед на файлове

[Tree] ORM: Remove "ORDER BY" DQL part in count queries to avoid errors with some db vendors.

comfortablynumb преди 13 години
родител
ревизия
0aea81bf77
променени са 1 файла, в които са добавени 11 реда и са изтрити 0 реда
  1. 11 0
      lib/Gedmo/Tree/Entity/Repository/AbstractTreeRepository.php

+ 11 - 0
lib/Gedmo/Tree/Entity/Repository/AbstractTreeRepository.php

@@ -100,6 +100,17 @@ abstract class AbstractTreeRepository extends EntityRepository implements Reposi
         }
 
         $qb = $this->getChildrenQueryBuilder($node, $direct);
+
+        // We need to remove the ORDER BY DQL part since some vendors could throw an error
+        // in count queries
+        $dqlParts = $qb->getDQLParts();
+
+        // We need to check first if there's an ORDER BY DQL part, because resetDQLPart doesn't
+        // check if its internal array has an "orderby" index
+        if (isset($dqlParts['orderby'])) {
+            $qb->resetDQLPart('orderby');
+        }
+
         $aliases = $qb->getRootAliases();
         $alias = $aliases[0];