Reputation: 167
HI, I want somehow to figure out which field was updated in the controller, I didn't found anything that might sound like what I'm trying to achieve in API doc for UnitOfWork. For example, I want to add on @PreUpdate code similar to this
/** @PreUpdate */
function updateAllIsDefaultFields(){
//only if $this->isDefault propery for this entity is changed to 1 from its previous state, then update all other entities so they all have isDefault to 0
//else, means that this field is not changed, don't do anything
}
Or this must be done from the controller on every action?
I know that I can do it every time just if $this->isDefault is set to 1, but I would like to avoid it for performance and I might find it useful for some other scenarios as well. Thanks in advance
Upvotes: 1
Views: 1504
Reputation: 5454
You will have to write an Event Subscriber. Probably using an onFlush
event, you can retrieve an Entities ChangeSet from the UnitOfWork to determine if a certain field has been updated and then do what ever you want.
Upvotes: 1