You signed in with another tab or window.Reload to refresh your session.You signed out in another tab or window.Reload to refresh your session.You switched accounts on another tab or window.Reload to refresh your session.Dismiss alert
bin/create-new-entity# assume it creates an entity with id 1bin/load-entity 1# Output should contain: PostLoad EventListener called for Entity\Test#1
Load the same entity by reference and access a property to trigger initialisation
bin/load-entity-by-reference-and-access-proprty 1# Output will NOT contain: PostLoad EventListener called
Explanation
When loading entities by first retrieving a reference and then letting it initialise, Doctrine does not trigger PostLoadevents. This happens neither if Doctrine implements the reference as a Proxy (Doctrine < 4.0 default behaviour)nor ifit uses a "ghost object" (EntityManager created with$config->enableNativeLazyObjects(true);, PHP >=8.4) this has notbeen tested yet.
If you depend on the PostLoad event to perform some initialisation logic (e.g. loading binary data into properties),this can lead to incomplete entity objects being used.
About
Demonstration on PostLoad listeners not being triggered when loading entities via reference