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

Commit 300c531f by Sascha Depold

merge

1 parent 6c68eb11
Showing with 20 additions and 10 deletions
...@@ -578,16 +578,25 @@ module.exports = (function() { ...@@ -578,16 +578,25 @@ module.exports = (function() {
attrValueHash[attr] = Utils.now() attrValueHash[attr] = Utils.now()
} }
if (options.validate === true) {
var validate = this.build(attrValueHash).validate()
if (validate !== null && Object.keys(validate).length > 0) {
return new Utils.CustomEventEmitter(function(emitter) { return new Utils.CustomEventEmitter(function(emitter) {
emitter.emit('error', validate) if (options.validate === true) {
}).run() this.build(attrValueHash).validate().success(function(errors) {
if (!!errors) {
emitter.emit('error', errors)
} else {
this
.QueryInterface
.bulkUpdate(this.tableName, attrValueHash, where, options)
.proxy(emitter)
} }
}.bind(this))
} else {
this
.QueryInterface
.bulkUpdate(this.tableName, attrValueHash, where, options)
.proxy(emitter)
} }
}.bind(this)).run()
return this.QueryInterface.bulkUpdate(this.tableName, attrValueHash, where, options)
} }
DAOFactory.prototype.describe = function(schema) { DAOFactory.prototype.describe = function(schema) {
......
...@@ -275,7 +275,7 @@ describe(Support.getTestDialectTeaser("DaoValidator"), function() { ...@@ -275,7 +275,7 @@ describe(Support.getTestDialectTeaser("DaoValidator"), function() {
Model.sync({ force: true }).success(function() { Model.sync({ force: true }).success(function() {
Model.create({name: 'World'}).success(function(model) { Model.create({name: 'World'}).success(function(model) {
model.updateAttributes({name: ''}).error(function(err) { model.updateAttributes({name: ''}).error(function(err) {
expect(err).to.deep.equal({ name: [ 'String is empty: name', 'String is empty: name' ] }) expect(err).to.deep.equal({ name: [ 'String is empty' ] })
done() done()
}) })
}) })
...@@ -296,7 +296,7 @@ describe(Support.getTestDialectTeaser("DaoValidator"), function() { ...@@ -296,7 +296,7 @@ describe(Support.getTestDialectTeaser("DaoValidator"), function() {
Model.sync({ force: true }).success(function() { Model.sync({ force: true }).success(function() {
Model.create({name: 'World'}).success(function(model) { Model.create({name: 'World'}).success(function(model) {
Model.update({name: ''}, {id: 1}).error(function(err) { Model.update({name: ''}, {id: 1}).error(function(err) {
expect(err).to.deep.equal({ name: [ 'String is empty: name', 'String is empty: name' ] }) expect(err).to.deep.equal({ name: [ 'String is empty' ] })
done() done()
}) })
}) })
...@@ -427,11 +427,12 @@ describe(Support.getTestDialectTeaser("DaoValidator"), function() { ...@@ -427,11 +427,12 @@ describe(Support.getTestDialectTeaser("DaoValidator"), function() {
it('should emit an error when we try to enter in a string for an auto increment key through .build().validate()', function(done) { it('should emit an error when we try to enter in a string for an auto increment key through .build().validate()', function(done) {
var user = this.User.build({id: 'helloworld'}) var user = this.User.build({id: 'helloworld'})
, errors = user.validate()
user.validate().success(function(errors) {
expect(errors).to.deep.equal({ id: [ 'ID must be an integer!' ] }) expect(errors).to.deep.equal({ id: [ 'ID must be an integer!' ] })
done() done()
}) })
})
it('should emit an error when we try to .save()', function(done) { it('should emit an error when we try to .save()', function(done) {
var user = this.User.build({id: 'helloworld'}) var user = this.User.build({id: 'helloworld'})
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!