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

ambiguous dynamic-ref explanation #11724

Closed
SwimmingPolar opened this issue Apr 29, 2022 · 0 comments
Closed

ambiguous dynamic-ref explanation #11724

SwimmingPolar opened this issue Apr 29, 2022 · 0 comments
Labels
docs This issue is due to a mistake or omission in the mongoosejs.com documentation
Milestone

Comments

@SwimmingPolar
Copy link

https://github.com/Automattic/mongoose/blob/master/docs/populate.md#dynamic-ref
Going through this docs, I found the code might be somewhat misleading.

const commentSchema = new Schema({
  body: { type: String, required: true },
  modelId: {
    type: Schema.Types.ObjectId,
    required: true,
    // Instead of a hardcoded model name in `ref`, `refPath` means Mongoose
    // will look at the `onModel` property to find the right model.
    refPath: 'onModel'
  },
  onModel: {
    type: String,
    required: true,
    enum: ['BlogPost', 'Product']
  }
});

...

const commentOnBook = await Comment.create({
  body: 'Great read',
  doc: book._id,
  docModel: 'Product'
});
const commentOnPost = await Comment.create({
  body: 'Very informative',
  doc: post._id,
  docModel: 'BlogPost'
});

I thought properties passed as 'doc' and 'docModel' would be transferred to 'modelId' and 'onModel'.

doc => modelId
docModel => onModel

After some digging maybe it's just typos, please confirm.

@IslandRhythms IslandRhythms added the docs This issue is due to a mistake or omission in the mongoosejs.com documentation label Apr 29, 2022
@vkarpov15 vkarpov15 added this to the 6.3.6 milestone May 6, 2022
@vkarpov15 vkarpov15 modified the milestones: 6.3.6, 6.3.7 Jun 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs This issue is due to a mistake or omission in the mongoosejs.com documentation
Projects
None yet
Development

No branches or pull requests

3 participants