al kaj
al kaj

Reputation: 197

Aliasing a database field from model class in nestjs/sequelize

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.

Upvotes: 2

Views: 571

Answers (1)

Dezzley
Dezzley

Reputation: 1835

Try passing the options object to the @Column decorator

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

Upvotes: 2

Related Questions