DDC-3005: Events::postLoad fires without filled associations #3736

Closed
opened 2026-01-22 14:26:36 +01:00 by admin · 14 comments
Owner

Originally created by @doctrinebot on GitHub (Mar 2, 2014).

Originally assigned to: @Ocramius on GitHub.

Jira issue originally created by user strate:

When we load entities throw one dql query like this:

SELECT e, joined*link FROM Entity LEFT JOIN e.link joined*link

In event subscriber, subscribed to postLoad event for instances of Entity property "link" of entity does not contains fetched in same query joined entity, and does not contains proxy object.

Tell me if failing test case needed.

Originally created by @doctrinebot on GitHub (Mar 2, 2014). Originally assigned to: @Ocramius on GitHub. Jira issue originally created by user strate: When we load entities throw one dql query like this: ``` SELECT e, joined*link FROM Entity LEFT JOIN e.link joined*link ``` In event subscriber, subscribed to postLoad event for instances of Entity property "link" of entity does not contains fetched in same query joined entity, and does not contains proxy object. Tell me if failing test case needed.
admin added the Improvement label 2026-01-22 14:26:36 +01:00
admin closed this issue 2026-01-22 14:26:36 +01:00
Author
Owner
@doctrinebot commented on GitHub (Mar 2, 2014): - depends on [DDC-3070: [GH-1001] [DDC-3005] Defer invoking of postLoad event to the end of hydration cycle.](http://www.doctrine-project.org/jira/browse/DDC-3070) - relates to [DDC-54: Trigger postLoad events and callbacks after associations have been initialized](http://www.doctrine-project.org/jira/browse/DDC-54)
Author
Owner

@doctrinebot commented on GitHub (Mar 2, 2014):

Comment created by @ocramius:

The postLoad event is fired without warranty that association entities/proxies will be set:

http://docs.doctrine-project.org/en/latest/reference/events.html#lifecycle-events

@doctrinebot commented on GitHub (Mar 2, 2014): Comment created by @ocramius: The `postLoad` event is fired without warranty that association entities/proxies will be set: http://docs.doctrine-project.org/en/latest/reference/events.html#lifecycle-events
Author
Owner

@doctrinebot commented on GitHub (Mar 3, 2014):

Comment created by strate:

But why? This shounds like involuntary restriction, and I think it can be fixed. Will my PR with fix accepted, or collaborators don't want to change this behaviour?

@doctrinebot commented on GitHub (Mar 3, 2014): Comment created by strate: But why? This shounds like involuntary restriction, and I think it can be fixed. Will my PR with fix accepted, or collaborators don't want to change this behaviour?
Author
Owner

@doctrinebot commented on GitHub (Mar 3, 2014):

Comment created by @ocramius:

[~strate] triggering postLoad in the correct moment in time (when all dependencies are loaded) requires a lot of additional complexity to be inserted in various locations of the ORM.

Since postLoad is supposed to be used like **wakeup and in general for simple tasks, this kind of refactoring/rewrite would be an overkill.

@doctrinebot commented on GitHub (Mar 3, 2014): Comment created by @ocramius: [~strate] triggering `postLoad` in the correct moment in time (when all dependencies are loaded) requires a lot of additional complexity to be inserted in various locations of the ORM. Since `postLoad` is supposed to be used like `**wakeup` and in general for simple tasks, this kind of refactoring/rewrite would be an overkill.
Author
Owner

@doctrinebot commented on GitHub (Mar 4, 2014):

Comment created by strate:

requires a lot of additional complexity to be inserted in various locations of the ORM.
Sounds like "It is very hard to implement, and no one want to do this"

and in general for simple tasks, this kind of refactoring/rewrite would be an overkill.
Disagree with this. Why only simple? I need to deal with associations in this event. Without this I should inject whole EntityManager to my entity, but I dont want to do this.

And I forced to repeat the question: will PR with fix accepted or not?

@doctrinebot commented on GitHub (Mar 4, 2014): Comment created by strate: > requires a lot of additional complexity to be inserted in various locations of the ORM. > Sounds like "It is very hard to implement, and no one want to do this" > > and in general for simple tasks, this kind of refactoring/rewrite would be an overkill. > Disagree with this. Why only simple? I **need** to deal with associations in this event. Without this I should inject whole EntityManager to my entity, but I dont want to do this. And I forced to repeat the question: will PR with fix accepted or not?
Author
Owner

@doctrinebot commented on GitHub (Mar 4, 2014):

Comment created by @ocramius:

{quote}Sounds like "It is very hard to implement, and no one want to do this"{quote}

Not really, the main problem here is performance, since hydration would have to be completely redesigned.
Yes, "too hard" is a good reason for something that is an edge case.

{quote}And I forced to repeat the question: will PR with fix accepted or not?{quote}

Sure thing! Just needs to avoid a massive rewrite though.

@doctrinebot commented on GitHub (Mar 4, 2014): Comment created by @ocramius: {quote}Sounds like "It is very hard to implement, and no one want to do this"{quote} Not really, the main problem here is performance, since hydration would have to be completely redesigned. Yes, "too hard" is a good reason for something that is an edge case. {quote}And I forced to repeat the question: will PR with fix accepted or not?{quote} Sure thing! Just needs to avoid a massive rewrite though.
Author
Owner

@doctrinebot commented on GitHub (Mar 4, 2014):

Comment created by @ocramius:

To give you some hints, Doctrine\ORM\Events::postLoad is triggered in 15432fc55f/lib/Doctrine/ORM/UnitOfWork.php (L2788), and Doctrine\ORM\UnitOfWork#createEntity() is used by all the various hydrators internally.

To ensure that Doctrine\ORM\Events::postLoad is triggered after an entity is fully loaded, the various hydrators must trigger the events after being sure that all data has been set, and that the entity is "ready" for use. That's some copy-paste work :\

@doctrinebot commented on GitHub (Mar 4, 2014): Comment created by @ocramius: To give you some hints, `Doctrine\ORM\Events::postLoad` is triggered in https://github.com/doctrine/doctrine2/blob/15432fc55f83c2d6ce8d9b86fd3139dd2a4fc328/lib/Doctrine/ORM/UnitOfWork.php#L2788, and `Doctrine\ORM\UnitOfWork#createEntity()` is used by all the various hydrators internally. To ensure that `Doctrine\ORM\Events::postLoad` is triggered after an entity is fully loaded, the various hydrators must trigger the events after being sure that all data has been set, and that the entity is "ready" for use. That's some copy-paste work :\
Author
Owner

@doctrinebot commented on GitHub (Mar 4, 2014):

Comment created by strate:

I think the entry point is here: 15432fc55f/lib/Doctrine/ORM/Internal/Hydration/AbstractHydrator.php (L140),
so, copy-paste work is not needed )

@doctrinebot commented on GitHub (Mar 4, 2014): Comment created by strate: I think the entry point is here: https://github.com/doctrine/doctrine2/blob/15432fc55f83c2d6ce8d9b86fd3139dd2a4fc328/lib/Doctrine/ORM/Internal/Hydration/AbstractHydrator.php#L140, so, copy-paste work is not needed )
Author
Owner

@doctrinebot commented on GitHub (Apr 5, 2014):

Comment created by strate:

PR is ready: https://github.com/doctrine/doctrine2/pull/1001

@doctrinebot commented on GitHub (Apr 5, 2014): Comment created by strate: PR is ready: https://github.com/doctrine/doctrine2/pull/1001
Author
Owner

@doctrinebot commented on GitHub (Oct 19, 2014):

Comment created by @doctrinebot:

A related Github Pull-Request [GH-1001] was assigned:
https://github.com/doctrine/doctrine2/pull/1001

@doctrinebot commented on GitHub (Oct 19, 2014): Comment created by @doctrinebot: A related Github Pull-Request [GH-1001] was assigned: https://github.com/doctrine/doctrine2/pull/1001
Author
Owner

@doctrinebot commented on GitHub (Oct 19, 2014):

Comment created by @doctrinebot:

A related Github Pull-Request [GH-1001] was unassigned:
https://github.com/doctrine/doctrine2/pull/1001

@doctrinebot commented on GitHub (Oct 19, 2014): Comment created by @doctrinebot: A related Github Pull-Request [GH-1001] was unassigned: https://github.com/doctrine/doctrine2/pull/1001
Author
Owner

@doctrinebot commented on GitHub (Jan 12, 2015):

Comment created by @doctrinebot:

A related Github Pull-Request [GH-1001] was closed:
https://github.com/doctrine/doctrine2/pull/1001

@doctrinebot commented on GitHub (Jan 12, 2015): Comment created by @doctrinebot: A related Github Pull-Request [GH-1001] was closed: https://github.com/doctrine/doctrine2/pull/1001
Author
Owner

@doctrinebot commented on GitHub (Jan 12, 2015):

Comment created by @ocramius:

Handled in DDC-3070

@doctrinebot commented on GitHub (Jan 12, 2015): Comment created by @ocramius: Handled in [DDC-3070](http://www.doctrine-project.org/jira/browse/DDC-3070)
Author
Owner

@doctrinebot commented on GitHub (Jan 12, 2015):

Issue was closed with resolution "Fixed"

@doctrinebot commented on GitHub (Jan 12, 2015): Issue was closed with resolution "Fixed"
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#3736