0 votes
1 view
in SQL by (22.4k points)

I have a model called User but Sequelize looks for the table USERS whenever I am trying to save in the DB. Does anyone know how to set Sequelize to use singular table names? Thanks.

1 Answer

0 votes
by (40.3k points)

Have a look at this example:

var Bar = sequelize.define('Bar', { /* bla */ }, {

  // don't add the timestamp attributes (updatedAt, createdAt)

  timestamps: false,

  // don't delete database entries but set the newly added attribute deletedAt

  // to the current date (when deletion was done). paranoid will only work if

  // timestamps are enabled

  paranoid: true,

  // don't use camelcase for automatically added attributes but underscore style

  // so updatedAt will be updated_at

  underscored: true,

  // disable the modification of tablenames; By default, sequelize will automatically

  // transform all passed model names (first parameter of define) into plural.

  // if you don't want that, set the following

  freezeTableName: true,

  // define the table's name

  tableName: 'my_very_custom_table_name'

})

This document will help you to use the property freezeTableName: https://sequelize.org/master/manual/models-definition.html#configuration

Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...