Merge pull request #540 from strongloop/fix/update-delete-all-details
Code cleanup in updateAll/deleteAll
This commit is contained in:
commit
abba2a88d9
14
lib/dao.js
14
lib/dao.js
|
@ -1302,7 +1302,7 @@ DataAccessObject.findOne = function findOne(query, options, cb) {
|
||||||
*
|
*
|
||||||
* @param {Object} [where] Optional object that defines the criteria. This is a "where" object. Do NOT pass a filter object.
|
* @param {Object} [where] Optional object that defines the criteria. This is a "where" object. Do NOT pass a filter object.
|
||||||
* @param {Object) [options] Options
|
* @param {Object) [options] Options
|
||||||
* @param {Function} [cb] Callback called with (err)
|
* @param {Function} [cb] Callback called with (err, info)
|
||||||
*/
|
*/
|
||||||
DataAccessObject.remove = DataAccessObject.deleteAll = DataAccessObject.destroyAll = function destroyAll(where, options, cb) {
|
DataAccessObject.remove = DataAccessObject.deleteAll = DataAccessObject.destroyAll = function destroyAll(where, options, cb) {
|
||||||
var connectionPromise = stillConnecting(this.getDataSource(), this, arguments);
|
var connectionPromise = stillConnecting(this.getDataSource(), this, arguments);
|
||||||
|
@ -1375,16 +1375,16 @@ DataAccessObject.remove = DataAccessObject.deleteAll = DataAccessObject.destroyA
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function done(err, data) {
|
function done(err, info) {
|
||||||
if (err) return cb(err);
|
if (err) return cb(err);
|
||||||
|
|
||||||
if (options.notify === false) {
|
if (options.notify === false) {
|
||||||
return cb(err, data);
|
return cb(err, info);
|
||||||
}
|
}
|
||||||
|
|
||||||
var context = { Model: Model, where: where, hookState: hookState };
|
var context = { Model: Model, where: where, hookState: hookState };
|
||||||
Model.notifyObserversOf('after delete', context, function(err) {
|
Model.notifyObserversOf('after delete', context, function(err) {
|
||||||
cb(err, data);
|
cb(err, info);
|
||||||
if (!err)
|
if (!err)
|
||||||
Model.emit('deletedAll', whereIsEmpty(where) ? undefined : where);
|
Model.emit('deletedAll', whereIsEmpty(where) ? undefined : where);
|
||||||
});
|
});
|
||||||
|
@ -1631,7 +1631,7 @@ DataAccessObject.prototype.save = function (options, cb) {
|
||||||
* @param {Object} [where] Search conditions (optional)
|
* @param {Object} [where] Search conditions (optional)
|
||||||
* @param {Object} data Changes to be made
|
* @param {Object} data Changes to be made
|
||||||
* @param {Object} [options] Options for update
|
* @param {Object} [options] Options for update
|
||||||
* @param {Function} cb Callback, called with (err, count)
|
* @param {Function} cb Callback, called with (err, info)
|
||||||
*/
|
*/
|
||||||
DataAccessObject.update =
|
DataAccessObject.update =
|
||||||
DataAccessObject.updateAll = function (where, data, options, cb) {
|
DataAccessObject.updateAll = function (where, data, options, cb) {
|
||||||
|
@ -1710,13 +1710,13 @@ DataAccessObject.updateAll = function (where, data, options, cb) {
|
||||||
}
|
}
|
||||||
|
|
||||||
var connector = Model.getDataSource().connector;
|
var connector = Model.getDataSource().connector;
|
||||||
connector.update(Model.modelName, where, data, function(err, count) {
|
connector.update(Model.modelName, where, data, function(err, info) {
|
||||||
if (err) return cb (err);
|
if (err) return cb (err);
|
||||||
var context = {
|
var context = {
|
||||||
Model: Model, where: where, data: data, hookState: hookState
|
Model: Model, where: where, data: data, hookState: hookState
|
||||||
};
|
};
|
||||||
Model.notifyObserversOf('after save', context, function(err, ctx) {
|
Model.notifyObserversOf('after save', context, function(err, ctx) {
|
||||||
return cb(err, count);
|
return cb(err, info);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue