Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Try passing the options object to the @Column decorator

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

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading