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

Schema composition does not work #9362

Closed
gilles-yvetot opened this issue Aug 27, 2020 · 3 comments
Closed

Schema composition does not work #9362

gilles-yvetot opened this issue Aug 27, 2020 · 3 comments
Milestone

Comments

@gilles-yvetot
Copy link

Do you want to request a feature or report a bug?
bug
What is the current behavior?
Schema composition does not work
If the current behavior is a bug, please provide the steps to reproduce.

const { Schema, model } = require('mongoose')

const StepSchema = new Schema(
  {
    view: {
      url: {
        type: String,
        trim: true,
      },
    },
  },
  { timestamps: true, discriminatorKey: `type` },
)

const ClickSchema = new Schema(
  [
    StepSchema,
    {
      view: {
        clickCount: {
          type: Number,
          default: 1,
          min: 1,
        },
      },
    },
  ],
  { discriminatorKey: `type` },
)

const Step = model(`Step`, StepSchema)

Step.discriminator(`click`, ClickSchema)

const doc = new Step({
  type: `click`,
  view: { url: `https://google.com` },
})

console.log('doc.view.url', doc.view.url)

What is the expected behavior?
doc.view.url to be defined
What are the versions of Node.js, Mongoose and MongoDB you are using? Note that "latest" is not a version.
Node 12.13.0 (NOT the browser environment)
Mongoose: 5.10.1
MongoDB: 4.2.8

@vkarpov15
Copy link
Collaborator

The issue here is that view from the 2nd schema definition overrides the view from the first schema definition. We'll see if we can add an option to merge these instead.

@vkarpov15 vkarpov15 added this to the 5.10.3 milestone Aug 28, 2020
@gilles-yvetot
Copy link
Author

Okay, got it. I was expected paths to be merged. If you cannot add the option, let me know and I'll hack around 👍

vkarpov15 added a commit that referenced this issue Aug 31, 2020
@vkarpov15
Copy link
Collaborator

Turns out there was a bug with our fix for #9042 that caused this issue. Fix will be in v5.10.3, thanks for reporting 👍

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