فهرست منبع

Fix issue #99, add documentation

Thomas Rabaix 14 سال پیش
والد
کامیت
82ebf5e636
4فایلهای تغییر یافته به همراه43 افزوده شده و 5 حذف شده
  1. 0 1
      Datagrid/ORM/Pager.php
  2. 7 4
      Datagrid/ORM/ProxyQuery.php
  3. 27 0
      Resources/doc/doctrine_orm/query_proxy.rst
  4. 9 0
      Resources/doc/index.rst

+ 0 - 1
Datagrid/ORM/Pager.php

@@ -42,7 +42,6 @@ class Pager extends BasePager
         return $countQuery->getSingleScalarResult();
         return $countQuery->getSingleScalarResult();
     }
     }
 
 
-
     /**
     /**
      * Get all the results for the pager instance
      * Get all the results for the pager instance
      *
      *

+ 7 - 4
Datagrid/ORM/ProxyQuery.php

@@ -70,14 +70,17 @@ class ProxyQuery implements ProxyQueryInterface
         $queryBuilderId->select($select);
         $queryBuilderId->select($select);
         $results  = $queryBuilderId->getQuery()->execute(array(), Query::HYDRATE_ARRAY);
         $results  = $queryBuilderId->getQuery()->execute(array(), Query::HYDRATE_ARRAY);
         $idx      = array();
         $idx      = array();
+        $connection = $queryBuilder->getEntityManager()->getConnection();
         foreach($results as $id) {
         foreach($results as $id) {
-            $idx[] = $id[$idName];
+            $idx[] = $connection->quote($id[$idName]);
         }
         }
 
 
         // step 4 : alter the query to match the targeted ids
         // step 4 : alter the query to match the targeted ids
-        $queryBuilder->andWhere(sprintf('%s IN (%s)', $select, implode(',', $idx)));
-        $queryBuilder->setMaxResults(null);
-        $queryBuilder->setFirstResult(null);
+        if (count($idx) > 0) {
+            $queryBuilder->andWhere(sprintf('%s IN (%s)', $select, implode(',', $idx)));
+            $queryBuilder->setMaxResults(null);
+            $queryBuilder->setFirstResult(null);
+        }
 
 
         return $queryBuilder;
         return $queryBuilder;
     }
     }

+ 27 - 0
Resources/doc/doctrine_orm/query_proxy.rst

@@ -0,0 +1,27 @@
+Doctrine ORM Proxy Query
+========================
+
+
+The ``ProxyQuery`` object is used to add missing features from the original Doctrine Query builder :
+
+  - ``execute`` method - no need to call the ``getQuery()`` method
+  - add sort by and sort order options
+  - add preselect id query on left join query, so a limit query will be only apply on the left statement and
+    not on the full select statement. This simulate the original Doctrine 1 behavior.
+
+
+.. code-block:: php
+
+    <?php
+    use Sonata\AdminBundle\Datagrid\ORM\ProxyQuery;
+
+    $queryBuilder = $this->em->createQueryBuilder();
+    $queryBuilder->from('Post', 'p');
+
+    $proxyQuery = new ProxyQuery($queryBuilder);
+    $proxyQuery->leftJoin('p.tags', t);
+    $proxyQuery->setSortBy('name');
+    $proxyQuery->setMaxResults(10);
+
+
+    $results = $proxyQuery->execute();

+ 9 - 0
Resources/doc/index.rst

@@ -25,6 +25,15 @@ Reference Guide
    reference/routing
    reference/routing
    reference/dashboard
    reference/dashboard
 
 
+Doctrine ORM
+------------
+
+.. toctree::
+   :maxdepth: 1
+   :numbered:
+
+   doctrine_orm/query_proxy
+
 
 
 Tutorial
 Tutorial
 --------
 --------