Chinese Documentation : Events

In addition to the standard Node events, LoopBack applications and models emit other events.

Application events

By default, the scaffolded application emits a 'started' event when it starts up, after running boot scripts.

Model events

The following table summarizes the events that LoopBack models can emit.

EventEmitted when...ArgumentsArgument typeClass methods that emitInstance methods that emit
'attached'

Model is attached to an app.

 


Model classObjectapp.model(modelName) 
'changed'Model instance is created, saved, or updated. Model instanceObject
  • Model.create()

  • Model.updateOrCreate() 

  • Model.upsert() 

  • Model.prototype.save()

  • Model.prototype.updateAttributes()

'dataSourceAttached'Model is attached to a Data source.Model classObject 
  • DataSource.prototype.createModel  
  • DataSource.prototype.define
'deleted'Model instance is deleted.Model IDNumber
  • Model.removeById()
  • Model.destroyById()
  • Model.deleteById()
  • Model.prototype.remove()
  • Model.prototype.delete()
  • Model.prototype.destroy()
 'deletedAll'Model instance is deleted.where (optional)JSON object
  • Model.remove()

  • Model.deleteAll()

  • Model.destroyAll()

 
'set'Model property is set.Model instanceObject 

Model.prototype.setAttributes()

Other events: