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

Commit 300c531f by Sascha Depold

merge

1 parent 6c68eb11
Showing with 26 additions and 16 deletions
......@@ -169,7 +169,7 @@ module.exports = (function() {
this.DAO.prototype.__factory = this
this.DAO.prototype.hasDefaultValues = !Utils._.isEmpty(this.DAO.prototype.defaultValues)
return this
}
......@@ -334,7 +334,7 @@ module.exports = (function() {
options = {where: parseInt(Number(options) || 0, 0)}
}
}
options.limit = 1
return this.QueryInterface.select(this, this.getTableName(), options, Utils._.defaults({
......@@ -578,16 +578,25 @@ module.exports = (function() {
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) {
emitter.emit('error', validate)
}).run()
return new Utils.CustomEventEmitter(function(emitter) {
if (options.validate === true) {
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)
}
}
return this.QueryInterface.bulkUpdate(this.tableName, attrValueHash, where, options)
}.bind(this)).run()
}
DAOFactory.prototype.describe = function(schema) {
......
......@@ -275,7 +275,7 @@ describe(Support.getTestDialectTeaser("DaoValidator"), function() {
Model.sync({ force: true }).success(function() {
Model.create({name: 'World'}).success(function(model) {
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()
})
})
......@@ -296,7 +296,7 @@ describe(Support.getTestDialectTeaser("DaoValidator"), function() {
Model.sync({ force: true }).success(function() {
Model.create({name: 'World'}).success(function(model) {
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()
})
})
......@@ -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) {
var user = this.User.build({id: 'helloworld'})
, errors = user.validate()
expect(errors).to.deep.equal({ id: [ 'ID must be an integer!' ] })
done()
user.validate().success(function(errors) {
expect(errors).to.deep.equal({ id: [ 'ID must be an integer!' ] })
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!