Fix replaceById unfound id bug

This commit is contained in:
Loay Gewily 2017-01-13 17:45:04 -05:00 committed by Loay Gewily
parent e384aa53ee
commit c232653c5d
1 changed files with 15 additions and 1 deletions

View File

@ -690,9 +690,23 @@ SQLConnector.prototype.update = function(model, where, data, options, cb) {
*/ */
SQLConnector.prototype._replace = function(model, where, data, options, cb) { SQLConnector.prototype._replace = function(model, where, data, options, cb) {
var stmt = this.buildReplace(model, where, data, options); var stmt = this.buildReplace(model, where, data, options);
this.execute(stmt.sql, stmt.params, options, cb); this.execute(stmt.sql, stmt.params, options, function(err, info) {
if (err) return cb(err);
if (info.affectedRows === 0) {
return cb(errorIdNotFoundForReplace(where.id));
} else {
return cb(null, info);
}
});
}; };
function errorIdNotFoundForReplace(idValue) {
var msg = g.f('Could not replace. Object with id %s does not exist!', idValue);
var error = new Error(msg);
error.statusCode = error.status = 404;
return error;
}
SQLConnector.prototype._executeAlteringQuery = function(model, sql, params, options, cb) { SQLConnector.prototype._executeAlteringQuery = function(model, sql, params, options, cb) {
var self = this; var self = this;
this.execute(sql, params, options, function(err, info) { this.execute(sql, params, options, function(err, info) {