-
-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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
Cannot define discriminator options on a Schema #14448
Labels
confirmed-bug
We've confirmed this is a bug in Mongoose and will fix it.
Milestone
Comments
IslandRhythms
added
the
confirmed-bug
We've confirmed this is a bug in Mongoose and will fix it.
label
Mar 21, 2024
const mongoose = require('mongoose');
const eventSchema = new mongoose.Schema({
name: String
});
const clickedEventSchema = new mongoose.Schema({ element: String }, { discriminatorKey: 'kind' });
eventSchema.discriminator('ClickedEvent', clickedEventSchema, { value: 'click' });
// ^ this will not be used
const Event = mongoose.model('Event', eventSchema);
const ClickedModel = mongoose.model('Clicked', clickedEventSchema);
async function run() {
await mongoose.connect('mongodb://localhost:27017');
await mongoose.connection.dropDatabase();
const doc = await Event.create({ kind: 'clicked', element: '#hero' });
doc.element; // '#hero'
console.log(doc instanceof ClickedModel); // this should be `true`, this will currently be `false`
console.log('done');
}
run(); |
vkarpov15
added a commit
that referenced
this issue
Apr 4, 2024
fix(schema): support setting discriminator options in Schema.prototype.discriminator()
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Prerequisites
Mongoose version
7.x.x, 8.x.x
Node.js version
20.x
MongoDB server version
7.2.2
Typescript version (if applicable)
No response
Description
While the
options
for a discriminator can be defined on aModel
,SchemaSubdocument
orSchemaDocumentArray
, they cannot be defined on a generalSchema
.Steps to Reproduce
Expected Behavior
Potential fix: master...forivall:mongoose:schema-discriminator-options
The text was updated successfully, but these errors were encountered: