mirror of
https://github.com/doctrine/orm.git
synced 2026-03-23 22:42:18 +01:00
Is there a way to trigger an event when a non-existent property is requested? #6231
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @yellow1912 on GitHub (Apr 24, 2019).
Support Question
So I know that we have postLoad event which I can hook to an entity. But my entity also has some custom properties that can be queried using some custom logic. I wonder if there is any event or something similar that can be triggered when a certain non-existent property is requested on the proxy object, that way I can hook into that event and provide the data? This is somewhat similar to the magic __get method of php class I think.
PS: I tried to use Slack but the link here has expired:
https://www.doctrine-project.org/community/
@Ocramius commented on GitHub (Apr 24, 2019):
@yellow1912 that's precisely what
__getis for, but the mechanism should work without ORM in first place. How would this work in an in-memory context, without ORM?@yellow1912 commented on GitHub (Apr 24, 2019):
I got creative about it, I used postLoad to set the EntityManager into a service, and this service into the entity when necessary, not very smart move I know. But it works and it has helped me to reduce 90% of my queries since now I only need to query the extra fields when absolutely necessary. Thank you for the suggestion with __get