不要怂,就是干,撸起袖子干!

Commit 4b4549d5 by Daniel Durante

DAOFactory.update() will now skip validations for columns that we're not updating. Closes #876

1 parent 65ee4e9d
......@@ -664,7 +664,10 @@ module.exports = (function() {
}
if (options.validate === true) {
var validate = this.build(attrValueHash).validate()
var build = this.build(attrValueHash)
, attrKeys = Object.keys(attrValueHash)
, validate = build.validate({skip: Object.keys(build.dataValues).filter(function(val) { return attrKeys.indexOf(val) !== -1 })})
if (validate !== null && Object.keys(validate).length > 0) {
return new Utils.CustomEventEmitter(function(emitter) {
emitter.emit('error', validate)
......
......@@ -254,6 +254,34 @@ describe(Support.getTestDialectTeaser("DaoValidator"), function() {
}
describe('#update', function() {
it('should allow us to update specific columns without tripping the validations', function(done) {
var User = this.sequelize.define('model', {
username: Sequelize.STRING,
email: {
type: Sequelize.STRING,
allowNull: false,
validate: {
isEmail: {
msg: 'You must enter a valid email address'
}
}
}
})
User.sync({ force: true }).success(function() {
User.create({username: 'bob', email: 'hello@world.com'}).success(function(user) {
User.update({username: 'toni'}, {id: user.id})
.error(function(err) { console.log(err) })
.success(function() {
User.find(1).success(function(user) {
expect(user.username).to.equal('toni')
done()
})
})
})
})
})
it('should be able to emit an error upon updating when a validation has failed from an instance', function(done) {
var Model = this.sequelize.define('model', {
name: {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!