Chinese Documentation : Basic model object

Overview

By default, a LoopBack model has properties and methods "mixed in" from:

When you define relations between models, the RelationMixin object object also gets mixed in to the model object.

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()