mirror of
https://github.com/doctrine/orm.git
synced 2026-03-23 22:42:18 +01:00
DDC-1401: Unusable entity in postRemove hook when using SINGLE_TABLE inheritance #1758
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 @doctrinebot on GitHub (Oct 4, 2011).
Originally assigned to: @beberlei on GitHub.
Jira issue originally created by user dbenjamin:
In a postRemove hook (from a dedicated listener, not inside an entity), the entity retrieved through Lifecycle event args is unusable when using SINGLE_TABLE inheritance.
Use case :
It works well if i use directly a Media object instead of a Picture one in my User class.
But as soon as i use a child object, here Picture, a 500 exception is systematically thrown when i try to access the entity given by the lifecycle event args.
This is really inconvenient since i can't perform any post remove operation when using inheritance system.
@doctrinebot commented on GitHub (Oct 15, 2011):
Comment created by @beberlei:
In your case i think the $media is a proxy object and then cannot be loaded in "postRemove" anymore.
Cant you just do that in preRemove (find the path)? And then work on postRemove() to delete it from a stack in the Media manager.
@doctrinebot commented on GitHub (Oct 15, 2011):
Comment created by @beberlei:
Invalid since in postRemove this can happen when you have an proxy and there is a workaround.
@doctrinebot commented on GitHub (Oct 15, 2011):
Issue was closed with resolution "Invalid"
@doctrinebot commented on GitHub (Oct 16, 2011):
Comment created by dbenjamin:
bq. Cant you just do that in preRemove (find the path)? And then work on postRemove() to delete it from a stack in the Media manager.
No i can't because the remove behaviour is not just about removing files and i need the informations about my entity.
I could register entities to be removed in the "preRemove" hook and do something with them later in the "postRemove" hook, but i assume the entities i would register would be Proxy objects too, so same problem.
Is there a way to retrieve the actual entity and not its proxy object ?
For now there is no workaround for my use case.
@doctrinebot commented on GitHub (Sep 21, 2014):
Comment created by acolomitchi:
Please review/reconsider. I fail to understand the reason why setting the id to null is necessary.
In my case, the entity (derived) is loaded (so no proxy).
I'm asking the entityManager to delete it (not to modify it). As such, when getting to the postRemove to:
a. delete file system resources (based on the id)
b. adjust an audit record
I find the id field set to null, so everything blows.
True, intercepting preRemove and scheduling the actual deletion to postRemove/postFlush may be a workaround, but why should it be done in such a contorted way? If the EM absolutely need to "damage" the deleted entity (ubder the risk of loosing the consistency), then how about passing the pre-existing values as separate parameters in the event?