1
0
mirror of synced 2025-01-29 19:41:45 +03:00

Clarifications and additions in DQL and Working with objects chapter

This commit is contained in:
Benjamin Eberlei 2011-06-11 08:59:33 +02:00
parent a5cfd2321f
commit 6f909b6e69
2 changed files with 11 additions and 1 deletions

View File

@ -253,6 +253,9 @@ Using Aggregate Functions:
$query = $em->createQuery('SELECT COUNT(u.id) FROM Entities\User u');
$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:
.. code-block:: php
@ -916,7 +919,7 @@ structure:
.. 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
[0]

View File

@ -690,6 +690,13 @@ methods on a repository as follows:
// A single user by its nickname
$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
calls through its use of ``__call``. Thus, the following two
examples are equivalent: