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

Creating a model using "new Model" should also respect discriminators #7586

Closed
ajwootto opened this issue Mar 5, 2019 · 0 comments
Closed
Milestone

Comments

@ajwootto
Copy link

ajwootto commented Mar 5, 2019

Referencing this issue: #3624

Currently if you have Model and Submodel discriminating on the field "kind", and you do:

let doc = await Model.create({kind: "SubModel"})

You end up with an instance of SubModel as the result. However, if you do:

let doc = new Model({kind: "SubModel"})

Then doc is an instance of Model, not SubModel. While I understand the argument in the above issue that a polymorphic constructor is kind of confusing, it seems like this current situation is now even more confusing because one method of creating a new document will return SubModel, and the other will return Model.

In the docs, these two types of constructors are described as interchangeable and this difference in discriminator behaviour is not documented anywhere that I can find.

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

No branches or pull requests

2 participants