DDC-2697: ObjectHydrator::hydrateRowData fails to hydrate first fetch joined entity #3378

Open
opened 2026-01-22 14:18:55 +01:00 by admin · 3 comments
Owner

Originally created by @doctrinebot on GitHub (Sep 20, 2013).

Originally assigned to: @beberlei on GitHub.

Jira issue originally created by user austinsmorris:

Let's say I have accounts, contacts, and contact types. Any given contact can have be any kind of contact type to any account. This is all managed through an account_contacts table with a 3-way composite PK of the contact_id, account_id, and type_id.

All of this translates to 4 entities, the account, contact, type, and accountContact entity. The id of the accountContact entity is the three other entities which is holds.

When I use query builder to retrieve the accountContacts based on some condition, and also fetch join contacts, accounts, and types so that they are eagerly loaded, the ObjectHydrator fails to load the first accountContact returned.

This is because the first time through hydrateRowData, the fetch joined entities are hydrated first. The problem is $this->_rsm->parentAliasMap[$dqlAlias] does not contain an entry for the accountContact (root entity). Not until an accountContact is hydrated does that get set. In the mean time, the other three entities were set to null because there is no parent alias yet (in version 2.4, this is line 405.

Subsequent loops through hydrateRowData work because by this time the parent alias is set. But that first row returned is always an accountContact containing three null objects.

Originally created by @doctrinebot on GitHub (Sep 20, 2013). Originally assigned to: @beberlei on GitHub. Jira issue originally created by user austinsmorris: Let's say I have accounts, contacts, and contact types. Any given contact can have be any kind of contact type to any account. This is all managed through an account_contacts table with a 3-way composite PK of the contact_id, account_id, and type_id. All of this translates to 4 entities, the account, contact, type, and accountContact entity. The id of the accountContact entity is the three other entities which is holds. When I use query builder to retrieve the accountContacts based on some condition, and also fetch join contacts, accounts, and types so that they are eagerly loaded, the ObjectHydrator fails to load the first accountContact returned. This is because the first time through hydrateRowData, the fetch joined entities are hydrated first. The problem is $this->_rsm->parentAliasMap[$dqlAlias] does not contain an entry for the accountContact (root entity). Not until an accountContact is hydrated does that get set. In the mean time, the other three entities were set to null because there is no parent alias yet (in version 2.4, this is line 405. Subsequent loops through hydrateRowData work because by this time the parent alias is set. But that first row returned is always an accountContact containing three null objects.
admin added the Bug label 2026-01-22 14:18:55 +01:00
Author
Owner

@doctrinebot commented on GitHub (Oct 26, 2013):

Comment created by @beberlei:

[~austinsmorris] Can you show the QueryBuilder select clause you are using? Have you tried sorting the accountContacts first?

$qb->select('accountContacts, contact, account, type')

This way it should definately work, and then there is also some attempts to resort this way if you dont have that, but its not always working.

@doctrinebot commented on GitHub (Oct 26, 2013): Comment created by @beberlei: [~austinsmorris] Can you show the QueryBuilder select clause you are using? Have you tried sorting the accountContacts first? ``` $qb->select('accountContacts, contact, account, type') ``` This way it should definately work, and then there is also some attempts to resort this way if you dont have that, but its not always working.
Author
Owner

@doctrinebot commented on GitHub (Dec 6, 2013):

Comment created by austinsmorris:

Sorry, I don't have the original select clause. I ended up doing something different and can't seem to find my original code.

@doctrinebot commented on GitHub (Dec 6, 2013): Comment created by austinsmorris: Sorry, I don't have the original select clause. I ended up doing something different and can't seem to find my original code.
Author
Owner

@doctrinebot commented on GitHub (Dec 6, 2013):

Comment created by @beberlei:

I have another person that reported a simliiar bug with reproducable test case. I hope to investigate this very soon.

@doctrinebot commented on GitHub (Dec 6, 2013): Comment created by @beberlei: I have another person that reported a simliiar bug with reproducable test case. I hope to investigate this very soon.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#3378