Module: loopback

Class: Model(data)

The base class for all models.

Inheriting from Model

var properties = {...};
var options = {...};
var MyModel = loopback.Model.extend('MyModel', properties, options);

Options

  • trackChanges - If true, changes to the model will be tracked. Required for replication.

Events

Event: changed

Emitted after a model has been successfully created, saved, or updated. Argument: inst, model instance, object

MyModel.on('changed', function(inst) {
  console.log('model with id %s has been changed', inst.id);
  // => model with id 1 has been changed
});

Event: deleted

Emitted after an individual model has been deleted. Argument: id, model ID (number).

MyModel.on('deleted', function(id) {
  console.log('model with id %s has been deleted', id);
  // => model with id 1 has been deleted
});

Event: deletedAll

Emitted after an individual model has been deleted. Argument: where (optional), where filter, JSON object.

MyModel.on('deletedAll', function(where) {
  if (where) {
    console.log('all models where ', where, ' have been deleted');
    // => all models where
    // => {price: {gt: 100}}
    // => have been deleted
  }
});

Event: attached

Emitted after a Model has been attached to an app.

Event: dataSourceAttached

Emitted after a Model has been attached to a DataSource.

Event: set

Emitted when model property is set. Argument: inst, model instance, object

MyModel.on('set', function(inst) {
  console.log('model with id %s has been changed', inst.id);
  // => model with id 1 has been changed
});
Arguments
Name Type Description
data Object
Class Properties
Name Type Description
Model.modelName String

The name of the model. Static property.

Model.dataSource DataSource

Data source to which the model is connected, if any. Static property.

Model.sharedMethod SharedClass

The strong-remoting SharedClass that contains remoting (and http) metadata. Static property.

settings Object

Contains additional model settings.

settings.http.path string

Base URL of the model HTTP route.

[{string}]

settings.acls Array of ACLs for the model.