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

Commit 300c531f by Sascha Depold

merge

1 parent 6c68eb11
Showing with 26 additions and 16 deletions
...@@ -169,7 +169,7 @@ module.exports = (function() { ...@@ -169,7 +169,7 @@ module.exports = (function() {
this.DAO.prototype.__factory = this this.DAO.prototype.__factory = this
this.DAO.prototype.hasDefaultValues = !Utils._.isEmpty(this.DAO.prototype.defaultValues) this.DAO.prototype.hasDefaultValues = !Utils._.isEmpty(this.DAO.prototype.defaultValues)
return this return this
} }
...@@ -334,7 +334,7 @@ module.exports = (function() { ...@@ -334,7 +334,7 @@ module.exports = (function() {
options = {where: parseInt(Number(options) || 0, 0)} options = {where: parseInt(Number(options) || 0, 0)}
} }
} }
options.limit = 1 options.limit = 1
return this.QueryInterface.select(this, this.getTableName(), options, Utils._.defaults({ return this.QueryInterface.select(this, this.getTableName(), options, Utils._.defaults({
...@@ -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) { return new Utils.CustomEventEmitter(function(emitter) {
var validate = this.build(attrValueHash).validate() if (options.validate === true) {
if (validate !== null && Object.keys(validate).length > 0) { this.build(attrValueHash).validate().success(function(errors) {
return new Utils.CustomEventEmitter(function(emitter) { if (!!errors) {
emitter.emit('error', validate) emitter.emit('error', errors)
}).run() } 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,10 +427,11 @@ describe(Support.getTestDialectTeaser("DaoValidator"), function() { ...@@ -427,10 +427,11 @@ 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()
expect(errors).to.deep.equal({ id: [ 'ID must be an integer!' ] }) user.validate().success(function(errors) {
done() expect(errors).to.deep.equal({ id: [ 'ID must be an integer!' ] })
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) {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!