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

v7 - hooks access to model + typescript definition #16851

Open
4 of 8 tasks
axeldvp opened this issue Dec 8, 2023 · 2 comments · May be fixed by #17020
Open
4 of 8 tasks

v7 - hooks access to model + typescript definition #16851

axeldvp opened this issue Dec 8, 2023 · 2 comments · May be fixed by #17020
Labels
type: feature For issues and PRs. For new features. Never breaking changes.

Comments

@axeldvp
Copy link

axeldvp commented Dec 8, 2023

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

I'm using hooks, and I would like to access model on beforeCount. I can access to model when using beforeFind, but not on beforeCount. Also, "Property model does not exist on type FindOptions", can you add typescript definition for "model" on FindOptions ?

beforeFind : {
where: { id: 1 },
limit: 1,
model: User,
plain: true,
transaction: undefined,
connection: undefined,
hooks: true,
rejectOnEmpty: undefined
}

beforeCount : {
where: { userId: 1 },
hooks: true,
transaction: undefined,
connection: undefined,
raw: true
}

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

I apply automatic filtering on find requests using a static model function, and I would like to apply it also on count requests.

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.

@axeldvp axeldvp added pending-approval Bug reports that have not been verified yet, or feature requests that have not been accepted yet type: feature For issues and PRs. For new features. Never breaking changes. labels Dec 8, 2023
@ephys
Copy link
Member

ephys commented Dec 13, 2023

While the model is present, it's an unintended consequence of how the findAll method works and should not be relied upon. For global hooks (hooks used on the sequelize instance), we'll add a separate parameter that indicates on which model instance the event was triggered

@ephys ephys removed the pending-approval Bug reports that have not been verified yet, or feature requests that have not been accepted yet label Dec 13, 2023
@axeldvp
Copy link
Author

axeldvp commented Dec 14, 2023

For global hooks (hooks used on the sequelize instance), we'll add a separate parameter that indicates on which model instance the event was triggered

Do you have any idea when this might happen ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: feature For issues and PRs. For new features. Never breaking changes.
Projects
None yet
2 participants