diff --git a/lib/sql.js b/lib/sql.js index 0556cfa..bccead2 100644 --- a/lib/sql.js +++ b/lib/sql.js @@ -889,10 +889,26 @@ SQLConnector.prototype._constructUpdateQuery = function(model, where, fields) { * @param {Function} cb The callback function */ SQLConnector.prototype.update = function(model, where, data, options, cb) { + var self = this; var stmt = this.buildUpdate(model, where, data, options); - this._executeAlteringQuery(model, stmt.sql, stmt.params, options, cb || NOOP); + this._executeAlteringQuery(model, stmt.sql, stmt.params, options, function(err, info) { + if (err) return cb(err); + if (where.id && info.count === 0) { + return cb(errorIdNotFoundForUpdate(where.id)); + } else { + return cb(null, info) || NOOP; + } + }); }; +function errorIdNotFoundForUpdate(idValue) { + var msg = g.f( + 'Could not update attributes. {{Object}} with {{id}} %s does not exist!', idValue); + var error = new Error(msg); + error.statusCode = error.status = 404; + return error; +} + /** * Replace all instances that match the where clause with the given data * @param {String} model The model name