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

Commit a8be8fc8 by Jan Aagaard Meier

Merge pull request #3385 from manmar92/master

bulkCreate validation with individualHooks returns an array of errors when validation fails. Fix #3356
2 parents 9ebfb19f f1ce9960
Showing with 32 additions and 1 deletions
...@@ -1351,7 +1351,11 @@ module.exports = (function() { ...@@ -1351,7 +1351,11 @@ module.exports = (function() {
return Promise.map(instances, function(instance) { return Promise.map(instances, function(instance) {
// hookValidate rejects with errors, validate returns with errors // hookValidate rejects with errors, validate returns with errors
if (options.individualHooks) { if (options.individualHooks) {
return instance.hookValidate(options); return instance.hookValidate(options).catch(function (err) {
if (err) {
errors.push({record: instance, errors: err});
}
});
} else { } else {
return instance.validate(options).then(function (err) { return instance.validate(options).then(function (err) {
if (err) { if (err) {
......
...@@ -2561,3 +2561,29 @@ describe(Support.getTestDialectTeaser('Model'), function() { ...@@ -2561,3 +2561,29 @@ describe(Support.getTestDialectTeaser('Model'), function() {
return this.sequelize.sync({force: true}); 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!