query_proxy.rst 834 B

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