diff --git a/lib/dao.js b/lib/dao.js index 87497476..38aeb5c1 100644 --- a/lib/dao.js +++ b/lib/dao.js @@ -2669,6 +2669,19 @@ DataAccessObject.updateAll = function(where, data, options, cb) { this.applyScope(query); this.applyProperties(data); + var doValidate = false; + if (options.validate === undefined) { + if (Model.settings.validateUpdate === undefined) { + if (Model.settings.automaticValidation !== undefined) { + doValidate = Model.settings.automaticValidation; + } + } else { + doValidate = Model.settings.validateUpdate; + } + } else { + doValidate = options.validate; + } + where = query.where; var context = { @@ -2696,14 +2709,17 @@ DataAccessObject.updateAll = function(where, data, options, cb) { inst = new Model(data, {applyDefaultValues: false}); } - // validation required - inst.isValid(function(valid) { - if (valid) { + if (doValidate === false) { + doUpdate(ctx.where, ctx.data); + } else { + // validation required + inst.isValid(function(valid) { + if (!valid) { + return cb(new ValidationError(inst)); + } doUpdate(ctx.where, ctx.data); - } else { - cb(new ValidationError(inst)); - } - }, options); + }, options); + } }); }); diff --git a/test/manipulation.test.js b/test/manipulation.test.js index 3bef0926..b6673115 100644 --- a/test/manipulation.test.js +++ b/test/manipulation.test.js @@ -2259,8 +2259,6 @@ describe('manipulation', function() { }); it('should not coerce invalid values provided in where conditions', function(done) { - // remove the validations since update/updateAll validates the model - delete Person.validations; Person.update({name: 'Brett Boe'}, {dob: 'notadate'}, function(err) { should.exist(err); err.message.should.equal('Invalid date: notadate'); diff --git a/test/validations.test.js b/test/validations.test.js index c3a2ee8c..773bf66a 100644 --- a/test/validations.test.js +++ b/test/validations.test.js @@ -51,6 +51,8 @@ describe('validations', function() { id: {type: Number, id: true, generated: false}, name: {type: String}, age: {type: Number}, + }, { + validateUpdate: true, }); Entry.validatesUniquenessOf('id'); db.automigrate(function(err) {