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

Commit b160a0c2 by Mick Hansen

fix(model): bulkCreate now sets isNewRecord: false on returned instances, closes #4522

1 parent 06703fbf
# Next # Next
- [FIXED] Calling set with dot.separated key on a JSON/JSONB attribute will not flag the entire object as changed [#4379](https://github.com/sequelize/sequelize/pull/4379)
- [ADDED] Expose Association constructor as `Sequelize.Association` - [ADDED] Expose Association constructor as `Sequelize.Association`
- [FIXED] Calling set with dot.separated key on a JSON/JSONB attribute will not flag the entire object as changed [#4379](https://github.com/sequelize/sequelize/pull/4379)
- [FIXED] instances returned from `bulkCreate` now has `isNewRecord: false` and should be updateable if using `returning: true` with dialects that support it.
# 3.9.0 # 3.9.0
- [ADDED] beforeRestore/afterRestore hooks [#4371](https://github.com/sequelize/sequelize/issues/4371) - [ADDED] beforeRestore/afterRestore hooks [#4371](https://github.com/sequelize/sequelize/issues/4371)
......
...@@ -2137,6 +2137,7 @@ Model.prototype.bulkCreate = function(records, options) { ...@@ -2137,6 +2137,7 @@ Model.prototype.bulkCreate = function(records, options) {
if (Array.isArray(results)) { if (Array.isArray(results)) {
results.forEach(function (result, i) { results.forEach(function (result, i) {
instances[i].set(self.primaryKeyAttribute, result[self.rawAttributes[self.primaryKeyAttribute].field], {raw: true}); instances[i].set(self.primaryKeyAttribute, result[self.rawAttributes[self.primaryKeyAttribute].field], {raw: true});
instances[i].isNewRecord = false;
}); });
} }
return results; return results;
......
...@@ -1450,6 +1450,21 @@ describe(Support.getTestDialectTeaser('Model'), function() { ...@@ -1450,6 +1450,21 @@ describe(Support.getTestDialectTeaser('Model'), function() {
}); });
}); });
it('should set isNewRecord = false', function() {
var self = this
, data = [{ username: 'Peter', secretValue: '42', uniqueName: '1' },
{ username: 'Paul', secretValue: '23', uniqueName: '2'}];
return this.User.bulkCreate(data).then(function() {
return self.User.findAll({order: 'id'}).then(function(users) {
expect(users.length).to.equal(2);
users.forEach(function (user) {
expect(user.isNewRecord).to.equal(false);
});
});
});
});
it('saves data with single quote', function() { it('saves data with single quote', function() {
var self = this var self = this
, quote = "Single'Quote" , quote = "Single'Quote"
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!