Is there a way to trigger an event when a non-existent property is requested? #6231

Closed
opened 2026-01-22 15:29:17 +01:00 by admin · 2 comments
Owner

Originally created by @yellow1912 on GitHub (Apr 24, 2019).

Q A
Version 2.6.x

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/

Originally created by @yellow1912 on GitHub (Apr 24, 2019). <!-- Fill in the relevant information below to help triage your issue. --> | Q | A |------------ | ----- | Version | 2.6.x ### 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/
admin closed this issue 2026-01-22 15:29:17 +01:00
Author
Owner

@Ocramius commented on GitHub (Apr 24, 2019):

@yellow1912 that's precisely what __get is for, but the mechanism should work without ORM in first place. How would this work in an in-memory context, without ORM?

@Ocramius commented on GitHub (Apr 24, 2019): @yellow1912 that's precisely what `__get` is for, but the mechanism should work without ORM in first place. How would this work in an in-memory context, without ORM?
Author
Owner

@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

@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
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#6231