diff --git a/lib/dao.js b/lib/dao.js index 276edf16..67e0d793 100644 --- a/lib/dao.js +++ b/lib/dao.js @@ -3130,8 +3130,9 @@ function(data, options, cb) { for (var i = 0, n = idNames.length; i < n; i++) { var idName = idNames[i]; if (data[idName] !== undefined && !idEquals(data[idName], inst[idName])) { - var err = new Error(g.f('{{id}} property (%s) ' + - 'cannot be updated from %s to %s'), idName, inst[idName], data[idName]); + var err = new Error(g.f('{{id}} cannot be updated from ' + + '%s to %s when forceId is set to true', + inst[idName], data[idName])); err.statusCode = 400; process.nextTick(function() { cb(err); diff --git a/test/optional-validation.test.js b/test/optional-validation.test.js index 95ac6f71..8ea7195d 100644 --- a/test/optional-validation.test.js +++ b/test/optional-validation.test.js @@ -308,6 +308,19 @@ describe('optional-validation', function() { d.updateAttributes({'name': NEW_NAME}, expectChangeSuccess(done)); }); }); + + it('returns an error when trying to update the id property when forceId is set to true', + function(done) { + ModelWithForceId.create({name: 'foo'}, function(err, model) { + if (err) return done(err); + model.updateAttributes({id: 123}, function(err) { + err.should.be.instanceOf(Error); + err.message.should.eql('id cannot be updated from ' + model.id + + ' to 123 when forceId is set to true'); + done(); + }); + }); + }); }); });