Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat!: add model parameter on model hooks run on sequelize if they don't have an instance, add afterCount #17020

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

ephys
Copy link
Member

@ephys ephys commented Jan 30, 2024

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

Closes #16851

Model hooks also run on the Sequelize instance. Some of them include the model instance the hook runs on, but some of them don't have such an instance to include.

I added the model class to them instead.

This would be a breaking change because the model was added as the first parameter, to make them behave similarly to the instance parameter of other model hooks.

This PR also adds the afterCount hook.

First draft before I add all tests in case this change is a no-go in its current state

TODO

  • Document which hooks receive the model
  • Document afterCount
  • Add hook tests

@ephys ephys changed the title feat!: add model parameter on model hooks run on sequelize if they don't have an instance feat!: add model parameter on model hooks run on sequelize if they don't have an instance, add afterCount Jan 30, 2024
@ephys
Copy link
Member Author

ephys commented Feb 10, 2024

Thinking about this more:

  • We should give the model definition, not the model itself, so this can be compatible with repository mode in the future
  • Because of this, we could expose the class that the model definition is attached to on the ModelDefinition class
  • I think we should give the ModelDefinition on all hooks, also to make it easier for repository mode users. I propose to add it as the last parameter of all model hooks. This would also simplify the typings.

@ephys ephys requested a review from a team as a code owner March 18, 2024 23:04
@ephys ephys requested review from WikiRik and removed request for a team March 18, 2024 23:04
@sequelize-bot sequelize-bot bot added the conflicted This PR has merge conflicts and will not be present in the list of PRs to review label Apr 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
conflicted This PR has merge conflicts and will not be present in the list of PRs to review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

v7 - hooks access to model + typescript definition
1 participant