Mura ORM Events - Mura Docs v7.0

Mura ORM Events

As covered in the Mura ORM Configuration section, any .CFC's discovered under a "../handlers/" directory within a "model" directory, will automatically be registered as custom event handlers. For example, ../model/handlers/myhandler.cfc.

In the Mura Events section, we learned the various events that are announced during the lifecycle of the application and each request. In addition to the events documented there, Mura also announces special events for basic "CRUD" activities such as when saving, updating, or deleting an entity. To leverage any of these events, you simply add your methods to your custom event handler(s).

Event Description
onBefore{EntityName}Save Announced before an entity is saved.
onAfter{EntityName}Save Announced after an entity is saved.
on{EntityName}Save Announced after an entity is saved.
onBefore{EntityName}Update Announced before an entity is updated.
onAfter{EntityName}Update Announced after an entity is updated.
onBefore{EntityName}Create Announced before an entity is created.
onAfter{EntityName}Create Announced after an entity is created.
onBefore{EntityName}Delete Announced before an entity is deleted.
onAfter{EntityName}Delete Announced after an entity is deleted.

The example below illustrates using one of the event handlers.

onBefore{Entity}Save(m) {
// accessing the bean
var bean = m.event('bean');
  // do something here
}

Supported ORM Entity Events

In addition to using an event handler, you could use an ORM Entity Event. The following table lists supported ORM Entity events. You could simply include any these methods in your entity's .CFC to provide custom logic where needed.

ORM Event Description
preLoad() This method is called before the load operation is complete or before the data is loaded from the database.
postLoad() This method is called after the load operation is complete.
preUpdate() This method is called before the update operation is complete.
postUpdate() This method is called after the update operation is complete.
preCreate() This method is called before the create operation is complete.
preInsert() This method is called before the insert operation is complete.
postCreate() This method is called after the create operation is complete.
postInsert() This method is called after the insert operation is complete.
preDelete() This method is called before the object is deleted.
postDelete() This method is called after the delete operation is complete.