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

Commit 08e8c92d by Mick Hansen

Merge branch 'BridgeAR-fix-bulkCreate'

2 parents d21fffdc a13fa96f
......@@ -2,6 +2,7 @@
- [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 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
#### Backwards compatibility changes
......
......@@ -275,7 +275,7 @@ module.exports = (function() {
Parameters: table name + list of hashes of attribute-value-pairs.
*/
/* istanbul ignore next */
bulkInsertQuery: function(tableName, attrValueHashes) {
bulkInsertQuery: function(tableName, attrValueHashes, options, modelAttributes) {
throwMethodUndefined('bulkInsertQuery');
},
......
......@@ -1334,11 +1334,7 @@ module.exports = (function() {
}
}).then(function() {
instances.forEach(function(instance) {
// Filter dataValues by options.fields
var values = {};
options.fields.forEach(function(field) {
values[field] = instance.dataValues[field];
});
var values = Utils.mapValueFieldNames(instance.dataValues, options.fields, self);
// set createdAt/updatedAt attributes
if (createdAtAttr && !values[createdAtAttr]) {
......@@ -1398,21 +1394,6 @@ module.exports = (function() {
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
var attributes = {};
for (var attr in self.tableAttributes) {
......
......@@ -163,12 +163,11 @@ var Utils = module.exports = {
fields.forEach(function(attr) {
if (dataValues[attr] !== undefined && !Model._isVirtualAttribute(attr)) {
values[attr] = dataValues[attr];
// Field name mapping
if (Model.rawAttributes[attr] && Model.rawAttributes[attr].field && Model.rawAttributes[attr].field !== attr) {
values[Model.rawAttributes[attr].field] = values[attr];
delete values[attr];
values[Model.rawAttributes[attr].field] = dataValues[attr];
} else {
values[attr] = dataValues[attr];
}
}
});
......
......@@ -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() {
var self = this
, 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!