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

Commit 1b7be3e8 by Mick Hansen

fix blank bulkCreates in postgres

1 parent 022cf04a
......@@ -295,11 +295,24 @@ module.exports = (function() {
bulkInsertQuery: function(tableName, attrValueHashes) {
var query = "INSERT INTO <%= table %> (<%= attributes %>) VALUES <%= tuples %> RETURNING *;"
, tuples = []
, serials = []
Utils._.forEach(attrValueHashes, function(attrValueHash, i) {
if (i === 0) {
Utils._.forEach(attrValueHash, function(value, key, hash) {
if (tables[tableName] && tables[tableName][key]) {
if (['bigserial', 'serial'].indexOf(tables[tableName][key]) !== -1) {
serials.push(key)
}
}
})
}
Utils._.forEach(attrValueHashes, function(attrValueHash) {
removeSerialsFromHash(tableName, attrValueHash)
tuples.push("(" +
Utils._.values(attrValueHash).map(function(value){
Utils._.map(attrValueHash, function(value, key){
if (serials.indexOf(key) !== -1) {
return 'DEFAULT';
}
return this.escape(value)
}.bind(this)).join(",") +
")")
......
......@@ -915,6 +915,8 @@ describe(Support.getTestDialectTeaser("HasMany"), function() {
})
})
})
}).on('sql', function (sql) {
console.log(sql)
})
})
})
......
......@@ -883,6 +883,17 @@ describe(Support.getTestDialectTeaser("DAOFactory"), function () {
})
})
it('should allow blank creates (with timestamps: false)', function (done) {
var Worker = this.sequelize.define('Worker', {}, {timestamps: false})
Worker.sync().done(function(err) {
Worker.bulkCreate([{}, {}]).done(function (err, workers) {
expect(err).not.to.be.ok
expect(workers).to.be.ok
done()
})
})
})
describe('enums', function() {
it('correctly restores enum values', function(done) {
var self = this
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!