Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 82ebf5e

Browse files
author
Thomas Rabaix
committedMay 16, 2011
Fix issue sonata-project#99, add documentation
1 parent 8f88afe commit 82ebf5e

File tree

4 files changed

+43
-5
lines changed

4 files changed

+43
-5
lines changed
 

‎Datagrid/ORM/Pager.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ public function computeNbResult()
4242
return $countQuery->getSingleScalarResult();
4343
}
4444

45-
4645
/**
4746
* Get all the results for the pager instance
4847
*

‎Datagrid/ORM/ProxyQuery.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,14 +70,17 @@ private function getFixedQueryBuilder(QueryBuilder $queryBuilder)
7070
$queryBuilderId->select($select);
7171
$results = $queryBuilderId->getQuery()->execute(array(), Query::HYDRATE_ARRAY);
7272
$idx = array();
73+
$connection = $queryBuilder->getEntityManager()->getConnection();
7374
foreach($results as $id) {
74-
$idx[] = $id[$idName];
75+
$idx[] = $connection->quote($id[$idName]);
7576
}
7677

7778
// step 4 : alter the query to match the targeted ids
78-
$queryBuilder->andWhere(sprintf('%s IN (%s)', $select, implode(',', $idx)));
79-
$queryBuilder->setMaxResults(null);
80-
$queryBuilder->setFirstResult(null);
79+
if (count($idx) > 0) {
80+
$queryBuilder->andWhere(sprintf('%s IN (%s)', $select, implode(',', $idx)));
81+
$queryBuilder->setMaxResults(null);
82+
$queryBuilder->setFirstResult(null);
83+
}
8184

8285
return $queryBuilder;
8386
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
Doctrine ORM Proxy Query
2+
========================
3+
4+
5+
The ``ProxyQuery`` object is used to add missing features from the original Doctrine Query builder :
6+
7+
- ``execute`` method - no need to call the ``getQuery()`` method
8+
- add sort by and sort order options
9+
- add preselect id query on left join query, so a limit query will be only apply on the left statement and
10+
not on the full select statement. This simulate the original Doctrine 1 behavior.
11+
12+
13+
.. code-block:: php
14+
15+
<?php
16+
use Sonata\AdminBundle\Datagrid\ORM\ProxyQuery;
17+
18+
$queryBuilder = $this->em->createQueryBuilder();
19+
$queryBuilder->from('Post', 'p');
20+
21+
$proxyQuery = new ProxyQuery($queryBuilder);
22+
$proxyQuery->leftJoin('p.tags', t);
23+
$proxyQuery->setSortBy('name');
24+
$proxyQuery->setMaxResults(10);
25+
26+
27+
$results = $proxyQuery->execute();

‎Resources/doc/index.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,15 @@ Reference Guide
2525
reference/routing
2626
reference/dashboard
2727

28+
Doctrine ORM
29+
------------
30+
31+
.. toctree::
32+
:maxdepth: 1
33+
:numbered:
34+
35+
doctrine_orm/query_proxy
36+
2837

2938
Tutorial
3039
--------

0 commit comments

Comments
 (0)
Please sign in to comment.