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

Commit a13fa96f by Mick Hansen

Merge branch 'fix-bulkCreate' of https://github.com/BridgeAR/sequelize into BridgeAR-fix-bulkCreate

Conflicts:
	changelog.md
2 parents d21fffdc 7fc6f21b
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
- [BUG] Fix showIndexQuery so appropriate indexes are returned when a schema is used - [BUG] Fix showIndexQuery so appropriate indexes are returned when a schema is used
- [BUG] Fix addIndexQuery error when the model has a schema - [BUG] Fix addIndexQuery error when the model has a schema
- [BUG] Fix app crash in sqlite while running in special unique constraint errors [3730](https://github.com/sequelize/sequelize/pull/3730) - [BUG] Fix app crash in sqlite while running in special unique constraint errors [3730](https://github.com/sequelize/sequelize/pull/3730)
- [BUG] Fix bulkCreate: do not insert NULL for undefined values [3729](https://github.com/sequelize/sequelize/pull/3729)
- [BUG] Fix API doc generation - [BUG] Fix API doc generation
#### Backwards compatibility changes #### Backwards compatibility changes
......
...@@ -275,7 +275,7 @@ module.exports = (function() { ...@@ -275,7 +275,7 @@ module.exports = (function() {
Parameters: table name + list of hashes of attribute-value-pairs. Parameters: table name + list of hashes of attribute-value-pairs.
*/ */
/* istanbul ignore next */ /* istanbul ignore next */
bulkInsertQuery: function(tableName, attrValueHashes) { bulkInsertQuery: function(tableName, attrValueHashes, options, modelAttributes) {
throwMethodUndefined('bulkInsertQuery'); throwMethodUndefined('bulkInsertQuery');
}, },
......
...@@ -1334,11 +1334,7 @@ module.exports = (function() { ...@@ -1334,11 +1334,7 @@ module.exports = (function() {
} }
}).then(function() { }).then(function() {
instances.forEach(function(instance) { instances.forEach(function(instance) {
// Filter dataValues by options.fields var values = Utils.mapValueFieldNames(instance.dataValues, options.fields, self);
var values = {};
options.fields.forEach(function(field) {
values[field] = instance.dataValues[field];
});
// set createdAt/updatedAt attributes // set createdAt/updatedAt attributes
if (createdAtAttr && !values[createdAtAttr]) { if (createdAtAttr && !values[createdAtAttr]) {
...@@ -1398,21 +1394,6 @@ module.exports = (function() { ...@@ -1398,21 +1394,6 @@ module.exports = (function() {
return Utils._.omit(instance.dataValues, self._virtualAttributes); return Utils._.omit(instance.dataValues, self._virtualAttributes);
}); });
var rawAttribute;
// Map field names
records.forEach(function(values) {
for (var attr in values) {
if (values.hasOwnProperty(attr)) {
rawAttribute = self.rawAttributes[attr];
if (rawAttribute.field && rawAttribute.field !== rawAttribute.fieldName) {
values[self.rawAttributes[attr].field] = values[attr];
delete values[attr];
}
}
}
});
// Map attributes for serial identification // Map attributes for serial identification
var attributes = {}; var attributes = {};
for (var attr in self.tableAttributes) { for (var attr in self.tableAttributes) {
......
...@@ -163,12 +163,11 @@ var Utils = module.exports = { ...@@ -163,12 +163,11 @@ var Utils = module.exports = {
fields.forEach(function(attr) { fields.forEach(function(attr) {
if (dataValues[attr] !== undefined && !Model._isVirtualAttribute(attr)) { if (dataValues[attr] !== undefined && !Model._isVirtualAttribute(attr)) {
values[attr] = dataValues[attr];
// Field name mapping // Field name mapping
if (Model.rawAttributes[attr] && Model.rawAttributes[attr].field && Model.rawAttributes[attr].field !== attr) { if (Model.rawAttributes[attr] && Model.rawAttributes[attr].field && Model.rawAttributes[attr].field !== attr) {
values[Model.rawAttributes[attr].field] = values[attr]; values[Model.rawAttributes[attr].field] = dataValues[attr];
delete values[attr]; } else {
values[attr] = dataValues[attr];
} }
} }
}); });
......
...@@ -1351,6 +1351,29 @@ describe(Support.getTestDialectTeaser('Model'), function() { ...@@ -1351,6 +1351,29 @@ describe(Support.getTestDialectTeaser('Model'), function() {
}); });
}); });
it('should not insert NULL for unused fields', function () {
var Beer = this.sequelize.define('Beer', {
style: Sequelize.STRING,
size: Sequelize.INTEGER,
});
return Beer.sync({force: true}).then(function () {
return Beer.bulkCreate([{
style: 'ipa'
}], {
logging: function(sql) {
if (dialect === 'postgres') {
expect(sql.indexOf('INSERT INTO "Beers" ("id","style","createdAt","updatedAt") VALUES (DEFAULT')).not.be.equal(-1);
} else if (dialect === 'mssql') {
expect(sql.indexOf('INSERT INTO [Beers] ([style],[createdAt],[updatedAt]) VALUES')).not.be.equal(-1);
} else { // mysql, sqlite, mariadb
expect(sql.indexOf('INSERT INTO `Beers` (`id`,`style`,`createdAt`,`updatedAt`) VALUES (NULL')).not.be.equal(-1);
}
}
});
});
});
it('properly handles disparate field lists', function() { it('properly handles disparate field lists', function() {
var self = this var self = this
, data = [{username: 'Peter', secretValue: '42', uniqueName: '1' }, , data = [{username: 'Peter', secretValue: '42', uniqueName: '1' },
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!