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

Error is thrown when base model's schema specifies options that are not reflected in discriminator model's schema #1818

Closed
flore2003 opened this issue Dec 4, 2013 · 11 comments
Labels
enhancement This issue is a user-facing general improvement that doesn't fix a bug or add a new feature
Milestone

Comments

@flore2003
Copy link

When 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.

@ashaffer
Copy link
Contributor

+1

@zabojad
Copy link

zabojad commented Jan 25, 2016

Same thing here, and agree with @flore2003...

@vkarpov15 vkarpov15 added this to the 5.0 milestone Jan 25, 2016
@vkarpov15 vkarpov15 added enhancement This issue is a user-facing general improvement that doesn't fix a bug or add a new feature discussion If you have any thoughts or comments on this issue, please share them! backwards-breaking labels Jan 25, 2016
@ztzven
Copy link

ztzven commented Mar 6, 2016

+1

@moleike
Copy link

moleike commented Mar 21, 2016

I run into this too, +1

@Tate-ad
Copy link

Tate-ad commented Mar 28, 2016

+1

@activatedgeek
Copy link

It looks like such a behavior is only for a subset of options. Not all.

@0xc00010ff
Copy link

var options = { discriminatorKey: 'type', timestamps: true }; gives me this error. Luckily I can just hardcode the timestamps, but it would be nice if this was supported.

@vkarpov15 vkarpov15 modified the milestones: 4.5, 5.0 May 31, 2016
@vkarpov15 vkarpov15 removed backwards-breaking discussion If you have any thoughts or comments on this issue, please share them! labels May 31, 2016
@vkarpov15
Copy link
Collaborator

Actually this looks like a dup of #3414, which means it should be fixed when 4.5 lands.

@ksloan
Copy link

ksloan commented Jun 14, 2017

Was this never fixed? Seeing this in 4.10.6.

@vkarpov15
Copy link
Collaborator

@ksloan this particular issue is fixed. If you're experiencing a similar issue, please open up a new issue with a repro script.

@cp4r3z
Copy link

cp4r3z commented May 28, 2020

fwiw, I see the same issue in 4.11.14 when my base schema options contains

{ "versionKey": false }

Removing it makes the error go away (because now both schemas default to "__v"

Perhaps my scenario is slightly different, but I don't understand how the original issue was fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement This issue is a user-facing general improvement that doesn't fix a bug or add a new feature
Projects
None yet
Development

No branches or pull requests