Merge pull request #90 from strongloop/fix/return-count-when-updating-or-deleting

Return count when updating or deleting models
This commit is contained in:
Simon Ho 2015-03-26 14:57:25 -07:00
commit 15c21b92e6
1 changed files with 15 additions and 2 deletions

View File

@ -641,6 +641,17 @@ MySQL.prototype.count = function count(model, callback, where) {
};
MySQL.prototype.update =
MySQL.prototype.updateAll = function(model, where, data, cb) {
var query = 'UPDATE ' + this.tableEscaped(model) + ' SET ' +
this.toFields(model, data) + ' ' + this.buildWhere(model, where);
this.query(query, function(err, info) {
var affectedRows = info && typeof info.affectedRows === 'number' ?
info.affectedRows : undefined;
cb && cb(err, {count: affectedRows});
});
};
/**
* Delete instances for the given model
@ -657,8 +668,10 @@ MySQL.prototype.destroyAll = function destroyAll(model, where, callback) {
}
this.query('DELETE FROM '
+ this.tableEscaped(model) + ' ' + this.buildWhere(model, where || {}),
function (err, data) {
callback && callback(err, data);
function(err, info) {
var affectedRows = info && typeof info.affectedRows === 'number' ?
info.affectedRows : undefined;
callback && callback(err, {count: affectedRows});
}.bind(this));
};