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

Commit 1cfbd333 by Nicolas Padula Committed by GitHub

fix(data-types): use proper field name for `ARRAY(ENUM)` (#13210)

1 parent 444f06f5
...@@ -480,7 +480,7 @@ module.exports = BaseTypes => { ...@@ -480,7 +480,7 @@ module.exports = BaseTypes => {
if (this.type instanceof BaseTypes.ENUM) { if (this.type instanceof BaseTypes.ENUM) {
castKey = `${Utils.addTicks( castKey = `${Utils.addTicks(
Utils.generateEnumName(options.field.Model.getTableName(), options.field.fieldName), Utils.generateEnumName(options.field.Model.getTableName(), options.field.field),
'"' '"'
) }[]`; ) }[]`;
} }
......
...@@ -437,6 +437,34 @@ if (dialect.match(/^postgres/)) { ...@@ -437,6 +437,34 @@ if (dialect.match(/^postgres/)) {
expect(user.permissions).to.deep.equal(['access', 'write']); expect(user.permissions).to.deep.equal(['access', 'write']);
}); });
it('should be able to insert a new record even with a redefined field name', async function() {
const User = this.sequelize.define('UserEnums', {
name: DataTypes.STRING,
type: DataTypes.ENUM('A', 'B', 'C'),
owners: DataTypes.ARRAY(DataTypes.STRING),
specialPermissions: {
type: DataTypes.ARRAY(DataTypes.ENUM([
'access',
'write',
'check',
'delete'
])),
field: 'special_permissions'
}
});
await User.sync({ force: true });
const user = await User.bulkCreate([{
name: 'file.exe',
type: 'C',
owners: ['userA', 'userB'],
specialPermissions: ['access', 'write']
}]);
expect(user.length).to.equal(1);
});
it('should fail when trying to insert foreign element on ARRAY(ENUM)', async function() { it('should fail when trying to insert foreign element on ARRAY(ENUM)', async function() {
const User = this.sequelize.define('UserEnums', { const User = this.sequelize.define('UserEnums', {
name: DataTypes.STRING, name: DataTypes.STRING,
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!