query_proxy.rst 836 B

1234567891011121314151617181920212223242526
  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 applied on the left statement and
  7. not on the full select statement. This simulates 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();