Skip to content

Commit

Permalink
fix(data-types): use proper field name for ARRAY(ENUM) (#13210)
Browse files Browse the repository at this point in the history
  • Loading branch information
nahog authored Jun 26, 2021
1 parent 444f06f commit 1cfbd33
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/dialects/postgres/data-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,7 @@ module.exports = BaseTypes => {

if (this.type instanceof BaseTypes.ENUM) {
castKey = `${Utils.addTicks(
Utils.generateEnumName(options.field.Model.getTableName(), options.field.fieldName),
Utils.generateEnumName(options.field.Model.getTableName(), options.field.field),
'"'
) }[]`;
}
Expand Down
28 changes: 28 additions & 0 deletions test/integration/dialects/postgres/dao.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,34 @@ if (dialect.match(/^postgres/)) {
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() {
const User = this.sequelize.define('UserEnums', {
name: DataTypes.STRING,
Expand Down

0 comments on commit 1cfbd33

Please # to comment.