I use Doctrine 2 objects. We have several objects that need to update related items when they are stored in the database. For example, when a user record is changed, we save it as a new record, and the "inactive" field is set to "false". However, we must set the field "inactive" for all previous entries for this user to "true". This is done to preserve the audit history. This is a Legacy database, so restructuring is not an option.
Since Doctrine saves objects by passing them to the persister object (persist :: ($ thisObj)), rather than an object that has a save method ( $thisObj->save()
), we cannot just extend the save method from the parent object. The only option I see here is to try expanding the persist object, but it looks like a goose flock that just waits.
I found some information about events, but I donβt see how to add them so that events light up with a certain function when a specific entity is saved.
How to add pre-save / post-save features to some of my entities?
source share