question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Behaviour with auto-pluralization of tables differs from sequelize

See original GitHub issue

Typically sequelize pluralises the model name to create tables, so that the table is called Users and the model is called User. That always made sense to me, since the table does contain multiple users.

By setting freezeTableName to true by default, sequelize-typescript behaves differently from sequelize in regards to the table names that are created. I tried to read up on https://github.com/RobinBuschmann/sequelize-typescript/issues/154 and https://github.com/RobinBuschmann/sequelize-typescript/pull/148 to understand why this was required, but I don’t think I understand… From the sequelize docs

About freezeTableName:

If freezeTableName is true, sequelize will not try to alter the model name to get the table name. Otherwise, the model name will be pluralized

About underscoredAll:

Converts camelCased model names to underscored table names if true. Will not change model name if freezeTableName is set to true

In particular I don’t understand what problem you’re referring to in this comment. I’ve just set freezeTableName to false in my own repository and so far things seem to work well. Was it that this would be a breaking change for sequelize-typescript?

Would you consider such a breaking change (which will match the behaviour of sequelize more closely) for v1.0.0?

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:10 (10 by maintainers)

github_iconTop GitHub Comments

2reactions
RobinBuschmanncommented, Apr 24, 2018

It is already possible to set default define options for all tables like so

new Sequelize({
  define: {/* Default options goes here */}
})

Nevertheless, freezeTableName is currently set while passing options via @Table annotation instead of using the global default options 🙈My fault…

0reactions
RobinBuschmanncommented, Jan 15, 2019

@C45tr0 If you like to - Any help is appreciated

Read more comments on GitHub >

github_iconTop Results From Across the Web

Behaviour with auto-pluralization of tables differs from sequelize
Typically sequelize pluralises the model name to create tables, so that the table is called Users and the model is called User.
Read more >
Model Basics | Sequelize
A model is an abstraction that represents a table in your database. In Sequelize, it is a class that extends Model. The model...
Read more >
How to make Sequelize use singular table names
If you require to have different model names for singuar and plural definitions you can pass name as a parameter in options of...
Read more >
The Comprehensive Sequelize Cheatsheet
Sequelize is the most famous Node ORM and is quite feature-rich, ... To define mappings between Model and Table, we can use the...
Read more >
How To Use Sequelize with Node.js and MySQL - DigitalOcean
Note: There is a difference between belongsTo() and hasOne() . belongsTo() will add the foreignKey on the source table, whereas hasOne() will ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found