Fix replaceById unfound id bug
This commit is contained in:
parent
e384aa53ee
commit
c232653c5d
16
lib/sql.js
16
lib/sql.js
|
@ -690,9 +690,23 @@ SQLConnector.prototype.update = function(model, where, data, options, cb) {
|
|||
*/
|
||||
SQLConnector.prototype._replace = function(model, where, data, options, cb) {
|
||||
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) {
|
||||
var self = this;
|
||||
this.execute(sql, params, options, function(err, info) {
|
||||
|
|
Loading…
Reference in New Issue