An application-wide event handler CFC can be defined to handle callback when any entity is inserted, updated, deleted, or retrieved. This CFC must be configured at the application level as an ORM setting:
The event handler CFC needs to implement the CFIDE.ORM.IEventHandler interface. This CFC gets the callbacks from all persistence-related events and handles them accordingly. In this case, a single CFC handles the events for all the CFCs.
This interface contains the following methods for the event handler CFC:
For application-wide event handler CFC, you need to specify the component name also along with other arguments.
The methods for application-wide event handler are:
preFlush(entity): This method is called before the flush operation is complete. This function can be overridden only in a global event handler for an application. CFCs for individual entities will not get this event call.
preUpdate(entity, Struct oldData): This method is called just before the object is updated. A struct of old data is passed to this method to know the original state of the entity being updated.
When you call the EntitySave() method on an object that is not loaded using EntityLoad(), it gets updated but the intercepter call fails. This happens because an empty map is created for the object and there is no previous data associated with it.
postDelete (entity): This method is called after the delete operation is complete.
If event handlers are defined in both persistent CFC and event handler CFC, the persistent CFC is given the callback before calling the application wide event handler.