You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When you set the underscore: true option in the @Table configuration and also use @IndexDecorator, Sequelize-Typescript doesn't remember/consider this setting when creating the Index.
e.g If you have a column name of emailAddress and the underscore:true option is set in the configuration. Sequelize-Typescript goes ahead to try creating a column with the name emailAddress instead of email_address which results in an error.
Expected behavior
The configuration option should be remembered and used when creating an index with the Index Decorator.
Steps to reproduce
Create a table
Add the underscore: true option to the table options
add a column that uses camelCase
add an index to that column e.g emailAddress
sequelize-typescript fails to create this index because it doesn't remember the underscore:true option initially set
Related code
import{Optional}from"sequelize";import{Table,Column,DataType,Index,PrimaryKey,Model}from"sequelize-typescript";interfaceUserAttributes{id: number;phoneNumber: string;password: string;emailAddress: string;userType: number;isActive: boolean;};interfaceUserCreationAttributesextendsOptional<UserAttributes,'id'|'emailAddress'|'phoneNumber'>{};
@Table({timestamps: true,tableName: 'user',underscored: true,/*** Using this syntax works as when debugging I noticed the issue and decided to use this syntax.* I guess this behaviour is ok since you're opting in to specifying the field yourself **/// indexes: [// { fields: ['email_address'], unique: true },// { fields: ['phone_number'], unique: true, },// ]})exportclassUserModelextendsModel<UserAttributes,UserCreationAttributes>{
@PrimaryKey
@Columnid: number;
@Index
@Column({allowNull: true,unique: true,type: DataType.STRING(255)})emailAddress: string;
@Index
@Column({allowNull: true,unique: true,type: DataType.STRING(32)})phoneNumber: string;
@Column({allowNull: false,type: DataType.SMALLINT})userType: number;
@Column({defaultValue: true,type: DataType.BOOLEAN})isActive: boolean;
@Column({allowNull: false,type: DataType.STRING(320)})password: string;};
Issue
Versions
Issue type
Actual behavior
When you set the
underscore: true
option in the@Table
configuration and also use@Index
Decorator, Sequelize-Typescript doesn't remember/consider this setting when creating the Index.e.g If you have a column name of emailAddress and the
underscore:true
option is set in the configuration. Sequelize-Typescript goes ahead to try creating a column with the nameemailAddress
instead ofemail_address
which results in an error.Expected behavior
The configuration option should be remembered and used when creating an index with the Index Decorator.
Steps to reproduce
underscore: true
option to the table optionsemailAddress
underscore:true
option initially setRelated code
@RobinBuschmann @Toxicable @lukashroch
The text was updated successfully, but these errors were encountered: