Clarifications and additions in DQL and Working with objects chapter
This commit is contained in:
parent
a5cfd2321f
commit
6f909b6e69
@ -253,6 +253,9 @@ Using Aggregate Functions:
|
|||||||
$query = $em->createQuery('SELECT COUNT(u.id) FROM Entities\User u');
|
$query = $em->createQuery('SELECT COUNT(u.id) FROM Entities\User u');
|
||||||
$count = $query->getSingleScalarResult();
|
$count = $query->getSingleScalarResult();
|
||||||
|
|
||||||
|
$query = $em->createQuery('SELECT u, count(g.id) FROM Entities\User u JOIN u.groups g GROUP BY u.id');
|
||||||
|
$result $query->getResult();
|
||||||
|
|
||||||
With WHERE Clause and Positional Parameter:
|
With WHERE Clause and Positional Parameter:
|
||||||
|
|
||||||
.. code-block:: php
|
.. code-block:: php
|
||||||
@ -916,7 +919,7 @@ structure:
|
|||||||
|
|
||||||
.. code-block:: php
|
.. code-block:: php
|
||||||
|
|
||||||
$dql = "SELECT u, 'some scalar string', count(u.groups) AS num FROM User u";
|
$dql = "SELECT u, 'some scalar string', count(u.groups) AS num FROM User u JOIN u.groups g GROUP BY u.id";
|
||||||
|
|
||||||
array
|
array
|
||||||
[0]
|
[0]
|
||||||
|
@ -690,6 +690,13 @@ methods on a repository as follows:
|
|||||||
// A single user by its nickname
|
// A single user by its nickname
|
||||||
$user = $em->getRepository('MyProject\Domain\User')->findOneBy(array('nickname' => 'romanb'));
|
$user = $em->getRepository('MyProject\Domain\User')->findOneBy(array('nickname' => 'romanb'));
|
||||||
|
|
||||||
|
You can also load by owning side associations through the repository:
|
||||||
|
|
||||||
|
$number = $em->find('MyProject\Domain\Phonenumber', 1234);
|
||||||
|
$user = $em->getRepository('MyProject\Domain\User')->findOneBy(array('phone' => $number->getId()));
|
||||||
|
|
||||||
|
Take not that this only works by passing the ID of the associated entity, not yet by passing the associated entity itself.
|
||||||
|
|
||||||
An EntityRepository also provides a mechanism for more concise
|
An EntityRepository also provides a mechanism for more concise
|
||||||
calls through its use of ``__call``. Thus, the following two
|
calls through its use of ``__call``. Thus, the following two
|
||||||
examples are equivalent:
|
examples are equivalent:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user