Error is thrown when base model's schema specifies options that are not reflected in discriminator model's schema
See original GitHub issueWhen using the new discriminator models, mongoose throws an error, if the base model’s schema specifies schema options that are not reflected in the discriminator model’s schema.
Here is a simple code snippet that shows the issue:
var BaseSchema = new mongoose.Schema({
"name": String
}, {
"versionKey": false
});
var DiscriminatorSchema = new mongoose.Schema({
"something": String
});
var Base = mongoose.model("Base", BaseSchema);
var Discriminator = Base.discriminator("Discriminator", DiscriminatorSchema);
The following error is thrown:
Error: Discriminator options are not customizable (except toJSON & toObject)
I understand that you can’t set schema options on a schema used in a discriminator model, but it should not be an issue the other way around. I would expect the schema options of the base schema to be “inherited” by the discriminator schema.
Issue Analytics
- State:
- Created 10 years ago
- Reactions:6
- Comments:11 (1 by maintainers)
Top Results From Across the Web
Mongoose discriminators and required/unique fields
It is logical that error would be thrown since Author introduced required field that Moderator does not have. How is that handled?
Read more >Mongoose v6.8.2: Schemas
Each schema maps to a MongoDB collection and defines the shape of the documents within ... To do so, we pass it into...
Read more >Schema generation rules · GitBook - Goswagger.Io
For each schema, go-swagger will generate one or more model types in go. ... Generated models uses no reflection except for enum and...
Read more >JSON Type Definition | Ajv JSON schema validator
JTD schema forms. JTD specification defines 8 different forms that the schema for JSON can take for one of most widely used data...
Read more >OpenAPI CodeGen Extensions - APIMatic Documentation
These settings will be globally applicable to all operations and schema ... the SDK will not throw an exception but instead pass the...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@ksloan this particular issue is fixed. If you’re experiencing a similar issue, please open up a new issue with a repro script.
Was this never fixed? Seeing this in 4.10.6.