Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hydration broken when aliasing a column of a joined relation #134

Open
Phennim opened this issue Apr 15, 2024 · 1 comment · May be fixed by #135
Open

Hydration broken when aliasing a column of a joined relation #134

Phennim opened this issue Apr 15, 2024 · 1 comment · May be fixed by #135

Comments

@Phennim
Copy link

Phennim commented Apr 15, 2024

After this commit (1d68711) 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"
             }
         }
     }
} 
*/ 
@alquerci
Copy link

alquerci commented Apr 15, 2024

Hello @Phennim

Nice catch.

I added failing test for this issue, see #135 (comment)

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants