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

Commit 0e7ce348 by arcdev1 Committed by Sushant

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

1 parent 19b620c2
Showing with 26 additions and 8 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;
...@@ -4118,4 +4118,4 @@ Model.insertOrUpdate = Model.upsert; ...@@ -4118,4 +4118,4 @@ Model.insertOrUpdate = Model.upsert;
_.extend(Model, associationsMixin); _.extend(Model, associationsMixin);
Hooks.applyTo(Model); Hooks.applyTo(Model);
module.exports = Model; module.exports = Model;
\ No newline at end of file
...@@ -2,18 +2,18 @@ ...@@ -2,18 +2,18 @@
const chai = require('chai'), const chai = require('chai'),
expect = chai.expect, expect = chai.expect,
Support = require(__dirname + '/../support'), Support = require(__dirname + '/../support'),
DataTypes = require('../../../lib/data-types'), DataTypes = require('../../../lib/data-types'),
current = Support.sequelize; current = Support.sequelize;
describe(Support.getTestDialectTeaser('Model'), () => { 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!