Events
Events in Spot are powered by the Sabre
EventEmitter, and are exposed to your
entity via the events
static method. This allows spot to load your custom
events when your entity’s mapper is first loaded.
Example Entity
on
method used here, the EventEmitter also has a once
method that will ensure your callback is only executed one time.
Events
beforeSave
Called before any save event through any method that saves an entity.
Returning false
from your event callback will not save the entity.
afterSave
Called after any save event through any method that saves an entity.
beforeInsert
Called before a new entity is inserted via the save
, insert
or create
method.
Returning false
from your event callback will not insert the entity.
afterInsert
Called after a new entity is inserted via the save
, insert
or create
method.
beforeUpdate
Called before a new entity is updated via the save
or update
method.
Returning false
from your event callback will not update the entity.
afterUpdate
Called after a new entity is updated via the save
or update
method.
beforeValidate
Called before validation is run. Triggered by every save event through any method that saves an entity.
Returning false
from your event callback will trigger an immediate validation
failure, will not run any other validations, and will not save the entity.
afterValidate
Called after validation is run. Triggered by every save event through any method that saves an entity.
Returning false
from your event callback will trigger a validation failure,
and will not save the entity.