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(model): respect discriminators with Model.validate() #12824

Merged
merged 6 commits into from Dec 26, 2022

Conversation

vkarpov15
Copy link
Collaborator

Fix #12621

Summary

Model.validate() just uses the model's schema, doesn't look for a discriminator key in obj. This PR fixes that issue. Also separated out Model.validate tests into a separate file.

Examples

Copy link
Collaborator

@AbdelrahmanHafez AbdelrahmanHafez left a comment

Choose a reason for hiding this comment

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

LGTM, thanks! 👍

Copy link
Collaborator

@IslandRhythms IslandRhythms left a comment

Choose a reason for hiding this comment

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

LGTM

@hasezoey
Copy link
Collaborator

well, after the change the error changed, but i cannot quite find the reason why it still complains about overwriting a model (all the files involved have a beforeEach to delete models)

maybe it is related that types.array.test.js sets mongoose like const mongoose = require('./common').mongoose; while the others do const mongoose = start.mongoose;

@vkarpov15
Copy link
Collaborator Author

@hasezoey afterEach() is intentional here. Not a big deal either way, afterEach() makes the tests pass so we'll use that.

@hasezoey
Copy link
Collaborator

afterEach() is intentional here.

what is different compared to beforeEach that would require a afterEach here unlike other test files? (just curious)

afterEach() makes the tests pass so we'll use that.

from what i can tell, it does not make it pass - that is why i had changed it to match the other test files (because of mocha's environment bleeding) ... maybe add a before to clean up before any of the tests in this file run?

@vkarpov15 vkarpov15 merged commit dc1d82f into master Dec 26, 2022
@hasezoey hasezoey deleted the vkarpov15/gh-12621 branch December 27, 2022 12:45
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.

Make Model.validate() respect discriminators when discriminator key is set
4 participants