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

Commit 3464ade4 by Mick Hansen

feat(model/attributes): support aliased serial attributes for bulkCreate in postgres

1 parent 01113d4f
...@@ -1230,8 +1230,17 @@ module.exports = (function() { ...@@ -1230,8 +1230,17 @@ module.exports = (function() {
} }
}); });
// Map attributes for serial identification
var attributes = {};
for (var attr in self.rawAttributes) {
attributes[attr] = self.rawAttributes[attr];
if (self.rawAttributes[attr].field) {
attributes[self.rawAttributes[attr].field] = self.rawAttributes[attr];
}
}
// Insert all records at once // Insert all records at once
return self.QueryInterface.bulkInsert(self.getTableName(), records, options, self).then(runAfterCreate); return self.QueryInterface.bulkInsert(self.getTableName(), records, options, attributes).then(runAfterCreate);
} else { } else {
// Records were already saved while running create / update hooks // Records were already saved while running create / update hooks
return runAfterCreate(); return runAfterCreate();
......
...@@ -423,8 +423,8 @@ module.exports = (function() { ...@@ -423,8 +423,8 @@ module.exports = (function() {
}); });
}; };
QueryInterface.prototype.bulkInsert = function(tableName, records, options, Model) { QueryInterface.prototype.bulkInsert = function(tableName, records, options, attributes) {
var sql = this.QueryGenerator.bulkInsertQuery(tableName, records, options, Model.rawAttributes); var sql = this.QueryGenerator.bulkInsertQuery(tableName, records, options, attributes);
return this.sequelize.query(sql, null, options); return this.sequelize.query(sql, null, options);
}; };
......
...@@ -7,10 +7,10 @@ var chai = require('chai') ...@@ -7,10 +7,10 @@ var chai = require('chai')
, Support = require(__dirname + '/../support') , Support = require(__dirname + '/../support')
, DataTypes = require(__dirname + "/../../lib/data-types") , DataTypes = require(__dirname + "/../../lib/data-types")
, dialect = Support.getTestDialect() , dialect = Support.getTestDialect()
, datetime = require('chai-datetime') , datetime = require('chai-datetime');
chai.use(datetime) chai.use(datetime);
chai.config.includeStack = true chai.config.includeStack = true;
describe(Support.getTestDialectTeaser("Model"), function () { describe(Support.getTestDialectTeaser("Model"), function () {
describe('attributes', function () { describe('attributes', function () {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!