Skip to content

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.

3 participants