Doctrine 2 - ORM
  1. Doctrine 2 - ORM
  2. DDC-3005

Events::postLoad fires without filled associations

    Details

    • Type: Bug Bug
    • Status: Reopened
    • Priority: Major Major
    • Resolution: Unresolved
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: None
    • Security Level: All
    • Labels:
      None

      Description

      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.

        Activity

        Hide
        Marco Pivetta added a comment -

        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

        Show
        Marco Pivetta added a comment - 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
        Hide
        Artur Eshenbrener added a comment -

        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?

        Show
        Artur Eshenbrener added a comment - 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?
        Hide
        Marco Pivetta added a comment -

        Artur Eshenbrener 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.

        Show
        Marco Pivetta added a comment - Artur Eshenbrener 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.
        Hide
        Artur Eshenbrener added a comment -

        > 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?

        Show
        Artur Eshenbrener added a comment - > 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?
        Hide
        Marco Pivetta added a comment -

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

        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.

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

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

        Show
        Marco Pivetta added a comment - Sounds like "It is very hard to implement, and no one want to do this" 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. And I forced to repeat the question: will PR with fix accepted or not? Sure thing! Just needs to avoid a massive rewrite though.
        Hide
        Marco Pivetta added a comment - - edited

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

        Show
        Marco Pivetta added a comment - - edited 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 :\
        Show
        Artur Eshenbrener added a comment - 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 )
        Hide
        Artur Eshenbrener added a comment -
        Show
        Artur Eshenbrener added a comment - PR is ready: https://github.com/doctrine/doctrine2/pull/1001

          People

          • Assignee:
            Marco Pivetta
            Reporter:
            Artur Eshenbrener
          • Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated: