فهرست منبع

as per sql standard the columns that are present in the order by must also be present in select distinct part.
Without the patch adminbundle doesn't work with postgresql which enforces that part of the standard.

Miha Vrhovnik 14 سال پیش
والد
کامیت
debede273b
1فایلهای تغییر یافته به همراه15 افزوده شده و 0 حذف شده
  1. 15 0
      Datagrid/ORM/ProxyQuery.php

+ 15 - 0
Datagrid/ORM/ProxyQuery.php

@@ -70,6 +70,21 @@ class ProxyQuery implements ProxyQueryInterface
         $queryBuilderId->resetDQLPart('select');
         $queryBuilderId->add('select', 'DISTINCT '.$select);
 
+        //for SELECT DISTINCT, ORDER BY expressions must appear in select list
+        /* Consider
+            SELECT DISTINCT x FROM tab ORDER BY y;
+        For any particular x-value in the table there might be many different y
+        values.  Which one will you use to sort that x-value in the output?
+        */
+        // todo : check how doctrine behave, potential SQL injection here ...
+        if ($this->getSortBy()) {
+            $sortBy = $this->getSortBy();
+            if (strpos($sortBy, '.') === false) { // add the current alias
+                $sortBy = $queryBuilderId->getRootAlias().'.'.$sortBy;
+            }
+            $queryBuilderId->addSelect($sortBy);
+        }
+        
         $results  = $queryBuilderId->getQuery()->execute(array(), Query::HYDRATE_ARRAY);
         $idx      = array();
         $connection = $queryBuilder->getEntityManager()->getConnection();