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

Closed
doctrinebot opened this Issue Mar 2, 2014 · 14 comments

2 participants

@doctrinebot

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.

@doctrinebot

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

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

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

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

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

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 :\

@doctrinebot

Comment created by strate:

PR is ready: #1001

@doctrinebot

Comment created by @doctrinebot:

A related Github Pull-Request [GH-1001] was assigned:
#1001

@doctrinebot

Comment created by @doctrinebot:

A related Github Pull-Request [GH-1001] was unassigned:
#1001

@doctrinebot

Comment created by @doctrinebot:

A related Github Pull-Request [GH-1001] was closed:
#1001

@doctrinebot

Comment created by @ocramius:

Handled in DDC-3070

@doctrinebot

Issue was closed with resolution "Fixed"

@Ocramius Ocramius was assigned by doctrinebot Dec 6, 2015
@doctrinebot doctrinebot added this to the 2.5 milestone Dec 6, 2015
@doctrinebot doctrinebot closed this Dec 6, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment