Skip to content

Loading…

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

Closed
doctrinebot opened this Issue · 2 comments

2 participants

@doctrinebot

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

@doctrinebot

Comment created by @beberlei:

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

@doctrinebot

Issue was closed with resolution "Can't Fix"

@beberlei beberlei was assigned by doctrinebot
@doctrinebot doctrinebot closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.