From 1af1ec2c4358c3bceda949888c1d7e6e57332ce8 Mon Sep 17 00:00:00 2001 From: Rand McKinney Date: Tue, 2 Sep 2014 11:11:36 -0700 Subject: [PATCH] Update model.js Correct event docs per https://groups.google.com/forum/#!topic/loopbackjs/61qd--Xkowo: - `deleted` event takes instance arg, not id. - Add docs for `set` event --- lib/models/model.js | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/lib/models/model.js b/lib/models/model.js index e490804c..0a6a5c91 100644 --- a/lib/models/model.js +++ b/lib/models/model.js @@ -28,6 +28,7 @@ var stringUtils = require('underscore.string'); * #### Event: `changed` * * Emitted after a model has been successfully created, saved, or updated. + * Argument: `inst`, model instance, object * * ```js * MyModel.on('changed', function(inst) { @@ -38,11 +39,12 @@ var stringUtils = require('underscore.string'); * * #### Event: `deleted` * - * Emitted after an individual model has been deleted. + * Emitted after an individual model has been deleted. + * Argument: `id`, model ID (number). * * ```js - * MyModel.on('deleted', function(inst) { - * console.log('model with id %s has been deleted', inst.id); + * MyModel.on('deleted', function(id) { + * console.log('model with id %s has been deleted', id); * // => model with id 1 has been deleted * }); * ``` @@ -50,11 +52,12 @@ var stringUtils = require('underscore.string'); * #### Event: `deletedAll` * * Emitted after an individual model has been deleted. + * Argument: `where` (optional), where filter, JSON object. * * ```js * MyModel.on('deletedAll', function(where) { * if(where) { - * console.log('all models where', where, 'have been deleted'); + * console.log('all models where ', where, ' have been deleted'); * // => all models where * // => {price: {gt: 100}} * // => have been deleted @@ -70,6 +73,18 @@ var stringUtils = require('underscore.string'); * * Emitted after a `Model` has been attached to a `DataSource`. * + * #### Event: set + * + * Emitted when model property is set. + * Argument: `inst`, model instance, object + * + * ```js + * MyModel.on('set', function(inst) { + * console.log('model with id %s has been changed', inst.id); + * // => model with id 1 has been changed + * }); + * ``` + * * @class * @param {Object} data * @property {String} modelName The name of the model