Automattic / Automattic/mongoose
Support populating using multiple candidate models
- Dominant language
- JavaScript
- Stars
- 27.5k
- Forks
- 4k
- Avg merge
- 2d 7h
- Merged PRs (30d)
- 35
Description
**Do you want to request a *feature* or report a *bug*?**
Feature
**What is the current behavior?**
Right now, without using `refPath`, there's no way to try populating using multiple models, in cases where you don't know the exact model.
```javascript
MyModel.find().populate({ path: 'user', model: ['Merchant', 'User'] }); // Try populating using 'Merchant', if no result try populating using 'User'
```
**If the current behavior is a bug, please provide the steps to reproduce.**
**What is the expected behavior?**
Should have some sort of mechanism to try populating using multiple models. Re: #10503
**What are the versions of Node.js, Mongoose and MongoDB you are using? Note that "latest" is not a version.**
5.x
Contributor guide
Research direction
The issue identifies populate() and refPath as the relevant entry points, but names no files or tests. Start by tracing how populate handles refPath and model selection, then determine the expected behavior when candidates do not match; done requires an agreed mechanism and coverage for multiple candidate models.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, mongodb, node.js
- Domain
- backend, database
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100