From 37124c4e0aacf3fc898a02be4ff9dcfe83331a47 Mon Sep 17 00:00:00 2001 From: "Jonathan H. Wage" Date: Wed, 2 Jun 2010 23:41:41 -0400 Subject: [PATCH] Adding section for custom hydrators. --- manual/en/dql-doctrine-query-language.txt | 28 +++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/manual/en/dql-doctrine-query-language.txt b/manual/en/dql-doctrine-query-language.txt index 233b46577..ac0c48c39 100755 --- a/manual/en/dql-doctrine-query-language.txt +++ b/manual/en/dql-doctrine-query-language.txt @@ -603,6 +603,34 @@ You can use the `getSingleScalarResult()` shortcut as well: [php] $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()->addHydrator('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 There are situations when a query you want to execute returns a very large result-set that needs