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

Commit b53bae57 by Konstantin Meiklyar Committed by Sushant

removeAttribute('id') results in undefined: null data value (#7318) (#7382)

* issue # 7318

fixes issue # 7318 - https://github.com/sequelize/sequelize/issues/7318

* test and change log

* formatting

* changed message

* Update changelog.md

* Update removeAttribute.test.js
1 parent a7e31040
...@@ -57,6 +57,7 @@ ...@@ -57,6 +57,7 @@
- [FIXED] Connection error when fetching OIDs for unspported types in Postgres 8.2 or below [POSTGRES] [#5254](https://github.com/sequelize/sequelize/issues/5254) - [FIXED] Connection error when fetching OIDs for unspported types in Postgres 8.2 or below [POSTGRES] [#5254](https://github.com/sequelize/sequelize/issues/5254)
- [FIXED] Expose OptimisticLockError on Sequelize object [#7291](https://github.com/sequelize/sequelize/pull/7291) - [FIXED] Expose OptimisticLockError on Sequelize object [#7291](https://github.com/sequelize/sequelize/pull/7291)
- [FIXED] Deleted paranoid records can be queried in the same second. [#7204](https://github.com/sequelize/sequelize/issues/7204)/[#7332](https://github.com/sequelize/sequelize/pull/7332) - [FIXED] Deleted paranoid records can be queried in the same second. [#7204](https://github.com/sequelize/sequelize/issues/7204)/[#7332](https://github.com/sequelize/sequelize/pull/7332)
- [FIXED] `removeAttribute('id')` results in `undefined: null` data value [#7318](https://github.com/sequelize/sequelize/issues/7318)
- [FIXED] `bulkCreate` now runs in O(N) time instead of O(N^2) time. [#4247](https://github.com/sequelize/sequelize/issues/4247) - [FIXED] `bulkCreate` now runs in O(N) time instead of O(N^2) time. [#4247](https://github.com/sequelize/sequelize/issues/4247)
## BC breaks: ## BC breaks:
......
...@@ -2908,7 +2908,7 @@ class Model { ...@@ -2908,7 +2908,7 @@ class Model {
// set id to null if not passed as value, a newly created dao has no id // set id to null if not passed as value, a newly created dao has no id
// removing this breaks bulkCreate // removing this breaks bulkCreate
// do after default values since it might have UUID as a default value // do after default values since it might have UUID as a default value
if (!defaults.hasOwnProperty(this.constructor.primaryKeyAttribute)) { if (this.constructor.primaryKeyAttribute && !defaults.hasOwnProperty(this.constructor.primaryKeyAttribute)) {
defaults[this.constructor.primaryKeyAttribute] = null; defaults[this.constructor.primaryKeyAttribute] = null;
} }
......
...@@ -23,5 +23,16 @@ describe(Support.getTestDialectTeaser('Model'), function() { ...@@ -23,5 +23,16 @@ describe(Support.getTestDialectTeaser('Model'), function() {
expect(Model.primaryKeyAttribute).to.be.undefined; expect(Model.primaryKeyAttribute).to.be.undefined;
expect(_.size(Model.primaryKeys)).to.equal(0); expect(_.size(Model.primaryKeys)).to.equal(0);
}); });
it('should not add undefined attribute after removing primary key', function () {
var Model = current.define('m', {
name: DataTypes.STRING
});
Model.removeAttribute('id');
const instance = Model.build();
expect(instance.dataValues).not.to.include.keys('undefined');
});
}); });
}); });
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!