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

Commit 7f97e23b by Mick Hansen

[model/bulkCreate] don't fail on blank arrays (fixes #1148)

1 parent 061004f0
...@@ -688,6 +688,12 @@ module.exports = (function() { ...@@ -688,6 +688,12 @@ module.exports = (function() {
Utils.validateParameter(fieldsOrOptions, Object, { deprecated: Array, optional: true, index: 2, method: 'DAOFactory#bulkCreate' }) Utils.validateParameter(fieldsOrOptions, Object, { deprecated: Array, optional: true, index: 2, method: 'DAOFactory#bulkCreate' })
Utils.validateParameter(options, 'undefined', { deprecated: Object, optional: true, index: 3, method: 'DAOFactory#bulkCreate' }) Utils.validateParameter(options, 'undefined', { deprecated: Object, optional: true, index: 3, method: 'DAOFactory#bulkCreate' })
if (!records.length) {
return new Utils.CustomEventEmitter(function(emitter) {
emitter.emit('success', [])
}).run();
}
options = Utils._.extend({ options = Utils._.extend({
validate: false, validate: false,
hooks: false hooks: false
......
...@@ -883,6 +883,18 @@ describe(Support.getTestDialectTeaser("DAOFactory"), function () { ...@@ -883,6 +883,18 @@ describe(Support.getTestDialectTeaser("DAOFactory"), function () {
}) })
}) })
it('should allow blank arrays (return immediatly)', function (done) {
var Worker = this.sequelize.define('Worker', {})
Worker.sync().done(function(err) {
Worker.bulkCreate([]).done(function (err, workers) {
expect(err).not.to.be.ok
expect(workers).to.be.ok
expect(workers.length).to.equal(0)
done()
})
})
})
it('should allow blank creates (with timestamps: false)', function (done) { it('should allow blank creates (with timestamps: false)', function (done) {
var Worker = this.sequelize.define('Worker', {}, {timestamps: false}) var Worker = this.sequelize.define('Worker', {}, {timestamps: false})
Worker.sync().done(function(err) { Worker.sync().done(function(err) {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!