-
-
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
Issue populating document referenced inside embedded discriminator #5970
Comments
I've managed to resolve this by trying out different population methods: 1. populate with string: 2. populate with object that has a nested object: {
path: 'items',
populate: {
path: 'author'
}
}; result: 3. populate with object that has a nested object and the referenced model: {
path: 'items',
populate: {
path: 'author',
model: 'Author'
}
}; result: 4. populate with object that has a multi-level path: {
path: 'items.author'
} result: 5. populate with object that has a multi-level path and the model: {
path: 'items.author',
model: 'Author'
} result: {
_id: '5a51edae70aa5a59d39b915b',
firstName: 'David',
lastName: 'Flanagan',
__v: 0
} summary Also, I was under the impression that referencing the model in the population object was not necessary, since I've already defined |
Upon further investigating, it's seems there's something up with the logic to determine which model to use for populating when using embedded discriminators. I've commented to this #4817 which was resolved for regular discriminators, but the issue rises again when using embedded discriminators. Any help or pointers would be greatly appreciated! |
Thanks for reporting, will investigate ASAP 👍 |
This is proving to be a very tricky bug to fix. The right syntax should be: {
path: 'items.author'
} Unfortunately that currently doesn't work because populate doesn't handle embedded discriminators properly yet, so do this as a workaround until we fix this issue. {
path: 'items.author',
model: 'Author'
} |
No problem, will do. If you'd have a workaround for #4817 as well, that would be awesome. Thanks for your quick feedback! |
What's the issue with #4817 ? I thought that one was already fixed... |
It was, and is, for regular discriminators. But it fails with the same error when using embedded discriminators. See my last comment in #4817 for a repro script. If you'd like me to open up a new issue, let me know! |
Please do! |
here you go #5983 |
Fixed in master and 4.x branch, fix will be in 5.0.2 and 4.13.10 |
Do you want to request a feature or report a bug?
I like to report what I think is a bug in 5.0.0-rc2
What is the current behavior?
I'm trying to populate a referenced document inside an embedded discriminator.
Populating works when storing the discriminator in a separate collection, but it doesn't when it's embedded.
Situation: Bundle has Item (Books or Ebooks) that refer to an Author
Repro script for 1, separate collections, the author is correctly populated
Repro script for 2, embedded discriminator, the author is not populated
What is the expected behavior?
Author needs to get populated when Items are embedded
Please mention your node.js, mongoose and MongoDB version.
The text was updated successfully, but these errors were encountered: