Doubt Sequelize Node.js

Asked

Viewed 672 times

2

In relation to sequelize i created a table in my pgadmin named TB_USER but I have a question when creating the model:

const Sequelize = require('sequelize');
const db = require('../config/dataBase');

const Users = db.define('users', {
    title:{
        type: Sequelize
    }
})

In relation to db.define('users' would I have to put the table name I created? If I didn’t put the sequelize will create this table users?

  • Yes, Sequelize will create the table, in your case, 'userss' with one more’s' at the end, because by default, Sequelize pluralizes the name of all created tables.

  • @Cmtecardeal vlw mano, if you want to add an answer I give vote on it.

1 answer

3


Yes, Sequelize will create the table, in your case, userss with one more s in the end, because by default, Sequelize pluralizes the name of all created tables.

To leave the table name in the singular, you can pass a third object in the method define with the attribute freezeTableName worthwhile true.

const Users = db.define('users', {
 title: {
    type: Sequelize.String
 }
}, { freezeTableName: true });

Browser other questions tagged

You are not signed in. Login or sign up in order to post.