Aliasing a database field from model class in nestjs/sequelize

Viewed 18

I am beginning with NestJs and chose to use Sequelize for database operations, I would like to know if it is possible to alias a database column in the model class as follows:

@ForeignKey(() => Relation)
@Column
relationId: number // This field's name in the database is relation_id

Basically, I want a way if that is possible to tell Sequelize that the database column name corresponding to relationId is relation_id

Thank you in advance for your help.

1 Answers

Try passing the options object to the @Column decorator

@ForeignKey(() => Relation)
@Column({ field: 'relation_id' })
relationId: number 
Related