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

fix: apply embedded discriminators to subdoc schemas before compiling top level model so middleware applies correctly #15001

Merged
merged 1 commit into from
Nov 4, 2024

Conversation

vkarpov15
Copy link
Collaborator

Fix #14961

Summary

We found in #14961 that subdocument discriminators created using Schema.prototype.discriminator() don't get 'validate' hooks applied correctly. That's because are calling applyEmbeddedDiscriminators() after Model.compile(). And Mongoose generally assumes that all middleware is registered before model compilation. This PR moves applyEmbeddedDiscriminators() up.

Examples

… top level model so middleware applies correctly

Fix #14961
@vkarpov15 vkarpov15 added this to the 8.8.1 milestone Nov 1, 2024
@vkarpov15 vkarpov15 merged commit 84032e9 into master Nov 4, 2024
58 checks passed
@hasezoey hasezoey deleted the vkarpov15/gh-14961 branch November 5, 2024 07:41
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.

Re-occurrence of embedded discriminator not calling pre('validate') (discriminator defined without path)
2 participants