DDC-504: HYDRATE_ARRAY doesn't function as expected (like D1) #629

Closed
opened 2026-01-22 12:45:05 +01:00 by admin · 5 comments
Owner

Originally created by @doctrinebot on GitHub (Apr 9, 2010).

Jira issue originally created by user spiffyjr:

HYDRATE_ARRAY doesn't function as I would expect it - that is, it doesn't function like Doctrine 1's HYDRATE_ARRAY. For example,

        $q = $this->_em->createQuery(
            'SELECT t, s, g, u
            FROM Models\Team t
            LEFT JOIN t.server AS s
            LEFT JOIN t.game AS g
            LEFT JOIN t.user AS u
            WHERE t.id = ?1'
        );
        $result = $q->execute(
            array(1 => $teamId),
            \Doctrine\ORM\Query::HYDRATE_ARRAY
        );

Gives me the result set (notice username is NOT inside a key of 'user' as would be the case with Doctrine 1)

Array (
            [0] => Array
                (
                    [0] => Array
                        (
                            [id] => 1
                            [game_id] => 1
                            [server_id] => 0
                            [user_id] => 45
                            [name] => Heroes of Rolla
                            [tag] => H04
                            [url] => 
                            [server] => 
                            [game] => Array
                                (
                                    [id] => 1
                                    [name] => Heroes of Newerth
                                    [developer] => S2 Games
                                    [url] => http://www.heroesofnewerth.com
                                    [platform] => PC
                                    [type] => Strategy
                                    [use_server] => 
                                )

                        )

                    [username] => SpiffyJr
                )

        )
Originally created by @doctrinebot on GitHub (Apr 9, 2010). Jira issue originally created by user spiffyjr: HYDRATE_ARRAY doesn't function as I would expect it - that is, it doesn't function like Doctrine 1's HYDRATE_ARRAY. For example, ``` $q = $this->_em->createQuery( 'SELECT t, s, g, u FROM Models\Team t LEFT JOIN t.server AS s LEFT JOIN t.game AS g LEFT JOIN t.user AS u WHERE t.id = ?1' ); $result = $q->execute( array(1 => $teamId), \Doctrine\ORM\Query::HYDRATE_ARRAY ); ``` Gives me the result set (notice username is NOT inside a key of 'user' as would be the case with Doctrine 1) ``` Array ( [0] => Array ( [0] => Array ( [id] => 1 [game_id] => 1 [server_id] => 0 [user_id] => 45 [name] => Heroes of Rolla [tag] => H04 [url] => [server] => [game] => Array ( [id] => 1 [name] => Heroes of Newerth [developer] => S2 Games [url] => http://www.heroesofnewerth.com [platform] => PC [type] => Strategy [use_server] => ) ) [username] => SpiffyJr ) ) ```
admin added the Bug label 2026-01-22 12:45:05 +01:00
admin closed this issue 2026-01-22 12:45:07 +01:00
Author
Owner

@doctrinebot commented on GitHub (Apr 9, 2010):

Comment created by spiffyjr:

Sorry, that first query should be:

               $q = $this->_em->createQuery(
            'SELECT t, s, g, u.username
            FROM Models\Team t
            LEFT JOIN t.server AS s
            LEFT JOIN t.game AS g
            LEFT JOIN t.user AS u
            WHERE t.id = ?1'
        );
        $result = $q->execute(
            array(1 => $teamId),
            \Doctrine\ORM\Query::HYDRATE_ARRAY
        );
@doctrinebot commented on GitHub (Apr 9, 2010): Comment created by spiffyjr: Sorry, that first query should be: ``` $q = $this->_em->createQuery( 'SELECT t, s, g, u.username FROM Models\Team t LEFT JOIN t.server AS s LEFT JOIN t.game AS g LEFT JOIN t.user AS u WHERE t.id = ?1' ); $result = $q->execute( array(1 => $teamId), \Doctrine\ORM\Query::HYDRATE_ARRAY ); ```
Author
Owner
@doctrinebot commented on GitHub (Apr 10, 2010): Comment created by @hobodave: Array hydration is not intended to function like D1. See: http://www.doctrine-project.org/documentation/manual/2_0/en/dql-doctrine-query-language#the-query-class:pure-and-mixed-results and http://www.doctrine-project.org/documentation/manual/2_0/en/dql-doctrine-query-language#the-query-class:hydration-mode-asumptions:scalar-hydration-details
Author
Owner

@doctrinebot commented on GitHub (Apr 10, 2010):

Issue was closed with resolution "Invalid"

@doctrinebot commented on GitHub (Apr 10, 2010): Issue was closed with resolution "Invalid"
Author
Owner

@doctrinebot commented on GitHub (Apr 10, 2010):

Comment created by romanb:

Thats right, this is expected behavior but I can see that the documentation is still not clear enough on that, especially there is no documentation yet for how to actually get partial objects (what you want in your query).

Long story short, in Doctrine 2 "foo.bar" where foo is an entity alias an bar a scalar field of the entity selects a scalar value, not an object. To select a partial object, you need this syntax:

SELECT t, s, g, partial u.{id,username} FROM ...

Note that, unlike in D1, the rest of the fields of a partial object can not be loaded lazily, so be careful with partial objects.

@doctrinebot commented on GitHub (Apr 10, 2010): Comment created by romanb: Thats right, this is expected behavior but I can see that the documentation is still not clear enough on that, especially there is no documentation yet for how to actually get partial objects (what you want in your query). Long story short, in Doctrine 2 "foo.bar" where foo is an entity alias an bar a scalar field of the entity selects a scalar value, not an object. To select a partial object, you need this syntax: ``` SELECT t, s, g, partial u.{id,username} FROM ... ``` Note that, unlike in D1, the rest of the fields of a partial object can not be loaded lazily, so be careful with partial objects.
Author
Owner

@doctrinebot commented on GitHub (Apr 10, 2010):

Comment created by spiffyjr:

Wonderful! I was hoping it was a misinterpretation (or missing altogether) of the docs but I was unable to find anything that said otherwise. I'm LOVING D2, keep up the good work.

@doctrinebot commented on GitHub (Apr 10, 2010): Comment created by spiffyjr: Wonderful! I was hoping it was a misinterpretation (or missing altogether) of the docs but I was unable to find anything that said otherwise. I'm LOVING D2, keep up the good work.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#629