Skip to content


DDC-3212: Remove ArrayHydrator logic #3998

doctrinebot opened this Issue · 6 comments

4 participants


Jira issue originally created by user @ocramius:

The Doctrine\ORM\Internal\Hydration\ArrayHydrator ( ) is currently very messy and complicated due to the lack of actual Doctrine\ORM\UnitOfWork references when working with it, since we are not dealing with objects.

In order to reduce the amount of bugs and code duplication when working with array hydration, I would simply suggest making use of the Doctrine\ORM\Internal\Hydration\ObjectHydrator ( ) and its siblings, and then extracting data coming from the results in it as an array.

This could be a simple reflection-based extraction (pseudo):

class ArrayHydrator
    public function hydrateAllData()
        foreach ($this->objectHydrator->hydrateAllData() as $object) {
            yield $this->extractData($object);

The point here is that array-based hydration is not the primary focus of the ORM, and users should probably rely on SQL only when they want array hydration.


Comment created by @ocramius:

Note: performance is one of our biggest requirements, and array hydration is meant to achieve that. As I stated above, plain SQL is probably better for this sort of operation, so the issue is more about deprecating the ArrayHydrator completely, providing utilities to manipulate SQL resultsets instead.


Comment created by SenseException:

I know of some intern projects, where the ArrayHydrator is used. It is right, that an ORM should be about objects, but that also counts for ScalarHydrator, and SingleScalarHydrator, which also aren't Object hydrator. Isn't there a way to reduce the complexity of the ArrayHydrator without ObjectHydrator? It would be a shame when a project build up with DQL Queries need to switch partially to SQL.

@Ocramius Ocramius was assigned by doctrinebot
@doctrinebot doctrinebot added this to the 3.0 milestone

@Ocramius I'm against removing this feature.
You are right, in some cases an array hydration may be odd, but it is helpful when trying to fetch a flat list of data:
In this case I simply want to have the IDs (a complete hydration is in this case not necessary), so I do a partial select on the ids and then I transform it to a flat list using array_column().

If the array hydration will be removed in 3.x, I don't see a simple way to fetch flat lists only or will be there some other approach to do that?
And yes, I'd like to use DQL for this since I love the way to think in models although I just need to fetch a flat list in that case.

Doctrine member

I think the same can be achieved with a simple "SELECT FROM MyApp\User u"


but when I run an object hydration, this is the only value that will be attached on the object or am I wrong?

Doctrine member

@Ma27 no, that would be partial hydration, which is expressed with a different (very specific) syntax (see )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.