doctrine1 icon indicating copy to clipboard operation
doctrine1 copied to clipboard

Hydration broken when aliasing a column of a joined relation

Open Phennim opened this issue 1 year ago • 1 comments

After this commit (https://github.com/FriendsOfSymfony1/doctrine1/commit/1d68711221c57bd7b96d71cb757dcbe0a242f4d5) we get a different result for queries where we alias a column of a relation.

$rs = Doctrine_Query::create()
            ->select('c.id, h.hours as hrs')
            ->from('Calculation c')
            ->innerJoin('c.History h')
            ->execute([], Doctrine_Core::HYDRATE_ARRAY);

var_dump($rs);

/*
// After the commit we get:
array(1) {
    [0]=> array(2) {
        ["id"]=> string(5) "1"
        ["hrs"]=> string(4) "3.00"
    }
} 

// Before it was this (and therefore also the expected result):
array(1) {
     [0]=> array(3) {
         ["id"]=> string(5) "1"
         ["hrs"]=> string(4) "3.00"
         ["History"]=> array(2) {
             [0]=> array(2) {
                 ["id"]=> string(4) "1"
                 ["hrs"]=> string(4) "3.00"
             }
             [1]=> array(2) {
                 ["id"]=> string(3) "2"
                 ["hrs"]=> string(4) "2.00"
             }
         }
     }
} 
*/ 

Phennim avatar Apr 15 '24 12:04 Phennim

Hello @Phennim

Nice catch.

I added failing test for this issue, see https://github.com/FriendsOfSymfony1/doctrine1/pull/135#issuecomment-2057573400

Rules are

  • Array hydration must always have
    • the primary key as array index on each item.
    • the relation on each item when at least one field of the relation is selected.
    • the relation identifier is always present even when not explicitly on DQL select. see

alquerci avatar Apr 15 '24 18:04 alquerci