1
0
mirror of synced 2024-12-15 15:46:02 +03:00

Merge branch 'master' of github.com:doctrine/orm-documentation

This commit is contained in:
beberlei 2010-06-10 23:27:28 +02:00
commit 50e35e6bdc

30
manual/en/dql-doctrine-query-language.txt Executable file → Normal file
View File

@ -596,13 +596,41 @@ hydration:
[php] [php]
$query = $em->createQuery('SELECT COUNT(a.id) FROM CmsUser u LEFT JOIN u.articles a WHERE u.username = ?1 GROUP BY u.id'); $query = $em->createQuery('SELECT COUNT(a.id) FROM CmsUser u LEFT JOIN u.articles a WHERE u.username = ?1 GROUP BY u.id');
$query->setParameter(1, 'jwage'); $query->setParameter(1, 'jwage');
$numArticles = $query->getResult(Query::HYDRATE_SCALAR); $numArticles = $query->getResult(Query::HYDRATE_SINGLE_SCALAR);
You can use the `getSingleScalarResult()` shortcut as well: You can use the `getSingleScalarResult()` shortcut as well:
[php] [php]
$numArticles = $query->getSingleScalarResult(); $numArticles = $query->getSingleScalarResult();
++++ Custom Hydration Modes
You can easily add your own custom hydration modes by first creating a class which extends `AbstractHydrator`:
[php]
namespace MyProject\Hydrators;
use Doctrine\ORM\Internal\Hydration\AbstractHydrator;
class CustomHydrator extends AbstractHydrator
{
protected function _hydrateAll()
{
return $this->_stmt->fetchAll(PDO::FETCH_ASSOC);
}
}
Next you just need to add the class to the ORM configuration:
[php]
$em->getConfiguration()->addCustomHydrationMode('CustomHydrator', 'MyProject\Hydrators\CustomHydrator');
Now the hydrator is ready to be used in your queries:
[php]
$query = $em->createQuery('SELECT u FROM CmsUser u');
$results = $query->getResult('CustomHydrator');
+++ Iterating Large Resultsets +++ Iterating Large Resultsets
There are situations when a query you want to execute returns a very large result-set that needs There are situations when a query you want to execute returns a very large result-set that needs