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(discriminator): handle reusing schema with embedded discriminators defined using Schema.prototype.discriminator #14202

Merged
merged 2 commits into from
Dec 30, 2023

Conversation

vkarpov15
Copy link
Collaborator

Fix #14162

Summary

#14162 points out that if you reuse a schema that has embedded discriminators defined using Schema.prototype.discriminator(), you'll get an OverwriteModelError because Mongoose already applied discriminators to the schema type. This PR makes it so that applying discriminators to the same SchemaType twice is a no-op.

Examples

…s defined using Schema.prototype.discriminator

Fix #14162
@vkarpov15 vkarpov15 added this to the 7.6.8 milestone Dec 28, 2023
@vkarpov15 vkarpov15 changed the base branch from master to 7.x December 28, 2023 23:34
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.

Looks good to me (aside from deno not liking something)

test/document.test.js Outdated Show resolved Hide resolved
@vkarpov15 vkarpov15 merged commit 3a015f9 into 7.x Dec 30, 2023
41 of 42 checks passed
@hasezoey hasezoey deleted the vkarpov15/gh-14162 branch December 30, 2023 18:10
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.

Reusing schema with discriminated field fails with "discriminator already exists" error
2 participants