diff --git a/lib/sql.js b/lib/sql.js index 1a02407..1f157ef 100644 --- a/lib/sql.js +++ b/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) {