Skip to content

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

Merged
vkarpov15 merged 1 commit intomasterfrom
vkarpov15/gh-14961
Nov 4, 2024
Merged

fix: apply embedded discriminators to subdoc schemas before compiling top level model so middleware applies correctly#15001
vkarpov15 merged 1 commit intomasterfrom
vkarpov15/gh-14961

Conversation

@vkarpov15
Copy link
Copy Markdown
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
@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