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(model): add mergeHooks option to Model.discriminator() to avoid duplicate hooks #12542

Merged
merged 2 commits into from Oct 17, 2022

Conversation

vkarpov15
Copy link
Collaborator

Fix #12472

Summary

There isn't a good way for Mongoose to dedupe hooks other than checking if you have two functions that are ===. Deduping based on toString() would prone to false positives with certain design patterns.

So for cases where deduping is not going to work, like #12472, we now have a mergeHooks option to Model.discriminator(). Model.discriminator(name, discriminatorSchema, { mergeHooks: false }) makes Mongoose take the discriminator schema's hooks.

Examples

Copy link
Collaborator

@hasezoey hasezoey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, but the new option is missing from the types

Copy link
Collaborator

@hasezoey hasezoey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@vkarpov15 vkarpov15 merged commit 8c84754 into 6.7 Oct 17, 2022
@vkarpov15 vkarpov15 deleted the vkarpov15/gh-12472 branch October 17, 2022 18:32
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.

None yet

2 participants