Skip to content

feat: throw if same model name is registered again - #15647

Closed
frostzt wants to merge 1 commit into
sequelize:mainfrom
frostzt:feat/throw-if-duplicate-schema-registered
Closed

frostzt wants to merge 1 commit into
sequelize:mainfrom
frostzt:feat/throw-if-duplicate-schema-registered

Conversation

@frostzt

@frostzt frostzt commented Feb 3, 2023

Copy link
Copy Markdown
Member

Pull Request Checklist

  • Have you added new tests to prevent regressions?
  • If a documentation update is necessary, have you opened a PR to the documentation repository?
  • Did you update the typescript typings accordingly (if applicable)?
  • Does the description below contain a link to an existing issue (Closes #[issue]) or a description of the issue you are solving?
  • Does the name of your PR follow our conventions?

Description Of Change

If the user tries to register models with a name that was already registered previously this should make the sequelize.define throw.

sequelize.define('model_already_present', { /* MODEL DEFINITION */ });

// This will throw!
sequelize.define('model_already_present', { /* MODEL DEFINITION */ });

Closes #15641

@frostzt
frostzt marked this pull request as draft February 3, 2023 20:57
@frostzt

frostzt commented Feb 5, 2023

Copy link
Copy Markdown
Member Author

Does this in any way relate to #15599 ?

@ephys

ephys commented Feb 6, 2023 •

Copy link
Copy Markdown
Member

Not directly, that PR was about preventing the same model from being initialized twice (calling .init twice on the same model for instance)

This PR is about registering two different models that have the same model name

Unsurprisingly, this change breaks many of our tests because the unit test suites define their models outside of beforeAll2/beforeEach2, so Sequelize is not reset between the creation of two models

@frostzt

frostzt commented Feb 6, 2023

Copy link
Copy Markdown
Member Author

@ephys I actually tried to use the resetSequelizeInstance method that we have seems like that won't budge too. This will require a bit of refactoring around the tests. Should I do that first in a different PR? What kinda structure would suit for those tests?

@ephys

ephys commented Mar 2, 2023

Copy link
Copy Markdown
Member

This will definitely require a good amount of refactoring as all model definitions in unit tests will need to move to beforeEach2 and beforeAll2 blocks. I do think it would be better to handle that in its own PR first but this is a very small PR so doing it here is fine too

@frostzt

frostzt commented Mar 3, 2023

Copy link
Copy Markdown
Member Author

@ephys I'll open a new PR for that refactor would be good for visibility!

@frostzt frostzt closed this by deleting the head repository Aug 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

2 participants