DDC-2710: Defer Hydrating an entity until its fields are accessed when using getReference even if its associated entities are accessed … #3392

Closed
opened 2026-01-22 14:19:09 +01:00 by admin · 2 comments
Owner

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

Originally assigned to: @beberlei on GitHub.

Jira issue originally created by user anandagra:

I feel it should be beneficial to not hydrate an entity even if its associations are accessed, when using getReference to create the entity instance,

reason behind,
sometimes we have a lot of associations and we are only interested in loading one, and do not require any property (excluding associations) from that entity,

this could save us one sql query, unit it is needed,

e.g.
Class User {
protected $id;
protected $username;
protected $password;

.....
.....

// one to many
protected $addresses;
}

$user = $em->getReference('..\User',1);
$user->getAddresses(); // this should only execute query against addresses table, and not to User table

Originally created by @doctrinebot on GitHub (Sep 27, 2013). Originally assigned to: @beberlei on GitHub. Jira issue originally created by user anandagra: I feel it should be beneficial to not hydrate an entity even if its associations are accessed, when using getReference to create the entity instance, reason behind, sometimes we have a lot of associations and we are only interested in loading one, and do not require any property (excluding associations) from that entity, this could save us one sql query, unit it is needed, e.g. Class User { protected $id; protected $username; protected $password; ..... ..... // one to many protected $addresses; } $user = $em->getReference('..\User',1); $user->getAddresses(); // this should only execute query against addresses table, and not to User table
admin added the Improvement label 2026-01-22 14:19:09 +01:00
admin closed this issue 2026-01-22 14:19:09 +01:00
Author
Owner

@doctrinebot commented on GitHub (Sep 27, 2013):

Comment created by @beberlei:

While this would be cool, this sadly is not possible with PHP. We cannot detect this correctly.

@doctrinebot commented on GitHub (Sep 27, 2013): Comment created by @beberlei: While this would be cool, this sadly is not possible with PHP. We cannot detect this correctly.
Author
Owner

@doctrinebot commented on GitHub (Sep 27, 2013):

Issue was closed with resolution "Can't Fix"

@doctrinebot commented on GitHub (Sep 27, 2013): Issue was closed with resolution "Can't Fix"
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#3392