You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have searched existing issues to ensure the bug has not already been reported
Mongoose version
8.2.2
Node.js version
18.16
MongoDB server version
6.3.0
Typescript version (if applicable)
No response
Description
I have a use case where I define a schema that uses a discriminated schema in a base package. I want to enable dependent packages to add their own implementations of the discriminated schema. However, it seems that once the model that uses the schema is compiled, adding further discriminated schemas are not applied.
Steps to Reproduce
'use strict';constmongoose=require('mongoose');const{ Schema }=mongoose;// Define discriminated schemaconstdecoratorSchema=newSchema({type: {type: String,required: true},},{discriminatorKey: "type"});classDecorator{type;whoAmI(){return"I am BaseDeco";}}decoratorSchema.loadClass(Decorator);// Define discriminated class before model is compiledclassDeco1extendsDecorator{whoAmI(){return"I am Deco1";}};constdeco1Schema=newSchema({}).loadClass(Deco1);deco1Schema.loadClass(Deco1);decoratorSchema.discriminator("Deco1",deco1Schema);// Define model that uses discriminated schemaconstshopSchema=newSchema({item: {type: decoratorSchema,required: true}});classShop{};shopSchema.loadClass(Shop);constshopModel=mongoose.model("shop",shopSchema);// Define another discriminated class after the model is compiledclassDeco2extendsDecorator{whoAmI(){return"I am Deco2";}};constdeco2Schema=newSchema({}).loadClass(Deco2);deco2Schema.loadClass(Deco2);decoratorSchema.discriminator("Deco2",deco2Schema);// Shouldn't recompiling the schema fix this?shopModel.recompileSchema();voidasyncfunctionmain(){letinstance=newshopModel({item: {type: "Deco1"}});// "I am Deco1" - Worksconsole.log(instance.item.whoAmI());instance=newshopModel({item: {type: "Deco2"}});// "I am BaseDeco" - Should be Deco2console.log(instance.item.whoAmI());}();
Expected Behavior
After recompiling a schema, it should also apply new discriminators of its fields.
The text was updated successfully, but these errors were encountered:
Prerequisites
Mongoose version
8.2.2
Node.js version
18.16
MongoDB server version
6.3.0
Typescript version (if applicable)
No response
Description
I have a use case where I define a schema that uses a discriminated schema in a base package. I want to enable dependent packages to add their own implementations of the discriminated schema. However, it seems that once the model that uses the schema is compiled, adding further discriminated schemas are not applied.
Steps to Reproduce
Expected Behavior
After recompiling a schema, it should also apply new discriminators of its fields.
The text was updated successfully, but these errors were encountered: