sequelize / sequelize/sequelize

Throw an error if the user tries to register two models with the same name

Open
#15,641 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
30.4k
Forks
4.3k
Avg merge
1d 6h
Merged PRs (30d)
68

Description

Issue Creation Checklist

  • I understand that my issue will be automatically closed if I don't fill in the requested information
  • I have read the contribution guidelines

Feature Description

Describe the feature you'd like to see implemented

Make the following impossible:

sequelize.define('User');
sequelize.define('User');

The second define should throw an error, because a model named User already exists in sequelize.models.

Describe why you would like this feature to be added to Sequelize

This behavior is dangerous and a source of bugs. Users should remove models manually, and we should ensure that that is possible (i.e. nothing depends on that model), before being able to register a model with the same name.

Example of an issue caused by this: https://github.com/sequelize/sequelize/issues/15639

Is this feature dialect-specific?
  • No. This feature is relevant to Sequelize as a whole.
  • Yes. This feature only applies to the following dialect(s):
Would you be willing to resolve this issue by submitting a Pull Request?
  • Yes, I have the time and I know how to start.
  • Yes, I have the time but I will need guidance.
  • No, I don't have the time, but my company or I are supporting Sequelize through donations on OpenCollective.
  • No, I don't have the time, and I understand that I will need to wait until someone from the community or maintainers is interested in implementing my feature.

Indicate your interest in the addition of this feature by adding the 👍 reaction. Comments such as "+1" will be removed.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at sequelize.define and inspect how models are registered in sequelize.models. Use the duplicate User definition and issue #15639 as context. Done means the second registration throws an error while allowing models to be removed and registered again when appropriate.

Written by the indexing model from the issue text.

Assessment

Tech stack
node.js, typescript
Domain
backend, databases
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.