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

Commit 0e7ce348 by arcdev1 Committed by Sushant

fix: ignore falsy attribute.unique property, fixed #8620 (#8625)

1 parent 19b620c2
Showing with 22 additions and 5 deletions
...@@ -994,7 +994,7 @@ class Model { ...@@ -994,7 +994,7 @@ class Model {
this._defaultValues[name] = _.partial(Utils.toDefaultValue, definition.defaultValue); this._defaultValues[name] = _.partial(Utils.toDefaultValue, definition.defaultValue);
} }
if (definition.hasOwnProperty('unique') && definition.unique !== false) { if (definition.hasOwnProperty('unique') && definition.unique) {
let idxName; let idxName;
if (typeof definition.unique === 'object' && definition.unique.hasOwnProperty('name')) { if (typeof definition.unique === 'object' && definition.unique.hasOwnProperty('name')) {
idxName = definition.unique.name; idxName = definition.unique.name;
......
...@@ -10,10 +10,10 @@ describe(Support.getTestDialectTeaser('Model'), () => { ...@@ -10,10 +10,10 @@ describe(Support.getTestDialectTeaser('Model'), () => {
describe('define', () => { describe('define', () => {
it('should allow custom timestamps with underscored: true', () => { it('should allow custom timestamps with underscored: true', () => {
const Model = current.define('User', {}, { const Model = current.define('User', {}, {
createdAt : 'createdAt', createdAt: 'createdAt',
updatedAt : 'updatedAt', updatedAt: 'updatedAt',
timestamps : true, timestamps: true,
underscored : true underscored: true
}); });
expect(Model.rawAttributes.createdAt).to.be.defined; expect(Model.rawAttributes.createdAt).to.be.defined;
...@@ -41,5 +41,22 @@ describe(Support.getTestDialectTeaser('Model'), () => { ...@@ -41,5 +41,22 @@ describe(Support.getTestDialectTeaser('Model'), () => {
}); });
}).to.throw("A column called 'id' was added to the attributes of 'bars' but not marked with 'primaryKey: true'"); }).to.throw("A column called 'id' was added to the attributes of 'bars' but not marked with 'primaryKey: true'");
}); });
it('should defend against null or undefined "unique" attributes', () => {
expect(() => {
current.define('baz', {
foo: {
type: DataTypes.STRING,
unique: null
},
bar: {
type: DataTypes.STRING,
unique: undefined
},
bop: {
type: DataTypes.DATE
}
});
}).not.to.throw();
});
}); });
}); });
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!