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

You need to sign in or sign up before continuing.
Commit d1b370e4 by Manuel Martinez

bulkCreate validation with individualHooks returns an array of errors when valid…

…ation fails. Fix #3356
1 parent 34ff44cf
Showing with 33 additions and 1 deletions
......@@ -1351,7 +1351,11 @@ module.exports = (function() {
return Promise.map(instances, function(instance) {
// hookValidate rejects with errors, validate returns with errors
if (options.individualHooks) {
return instance.hookValidate(options);
return instance.hookValidate(options).catch(function (err) {
if (err) {
errors.push({record: instance, errors: err});
}
});
} else {
return instance.validate(options).then(function (err) {
if (err) {
......
......@@ -2561,3 +2561,30 @@ describe(Support.getTestDialectTeaser('Model'), function() {
return this.sequelize.sync({force: true});
});
});
it('should return array of errors if validate and individualHooks are true in bulkCreate', function() {
var self = this
, data = [{ username: null },
{ username: null },
{ username: null }];
var user = this.sequelize.define('Users', {
username: {
type: Sequelize.STRING,
allowNull: false,
validate: {
notNull: true,
notEmpty: true
}
}
});
user.bulkCreate(data, {
validate: true,
individualHooks: true
})
.catch(function(errors) {
expect(errors).to.be.instanceof(Array);
});
});
\ No newline at end of file
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!