-
-
Notifications
You must be signed in to change notification settings - Fork 3.9k
.populate() does not work from a base schema, using discriminators, when the related collection is defined in the polymorphic child. #2719
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
Comments
Hmm can you let me know what |
It's just an instance of the BaseSchema, I've updated the example. |
@ericsaboia this is by design. The schema underlying |
Are you sure? because even when you query by the Base model, the returned object it's a instance of its child, and contains all the child fields: For example: Base.find({}, function(err, events) {
expect.ok(events[0] instanceof Conversion); // true
console.log(events[0].owner) // Owner ObjectId
}); So in my opinion it's worth the implementation. |
True, but when you call |
It's a feed on a social app. My base model it's called Activity, and then I have a lot of specialised types of Activity (checkin, post, promotion, and so on) Some of my Activity's children have specific relations, so it's not declared at the base model (Activity). At my feed service, I need to return a list of all kind of activities, with the populates necessary to fill the client. Ps: the result is cached, that's why I decided to keep the call to "populate" instead of copy the necessary fields from the related collections. |
So in 3.x there's no way to populate from multiple models - one populate() call <=> one model. @chetverikov added the ability to populate from multiple models into 4.x so this may be more feasible now. I'll re-open this issue and see how feasible it is for a future release. |
Hi @vkarpov15 I'm with the same problem but i saw that you close the issue this means that now should be possible populate a child of a specialisation? |
Yep see PR #2773 courtesy of @chetverikov |
Well, I'm using Mongoose 4.0.1 and I can't populate a collection in one specialisation.
Here is how I'm trying using populate unsuccessfully.
This is an example of my data collection events
This is the output with query result
I can't see where is my mistake or if the fix did not work. |
@vkarpov15 @diegodfsd |
Do you will release a new version with this fix when? |
cheers @chetverikov! |
No problem @chetverikov |
Edit: opened separate issue instead. |
mongoose version: "^3.8.19"
related to: #1647
When you use discriminators, and want to query from the base schema, populating some related collection, which was defined in the polymorphic child schema, the query runs, but the result goes without the related population objects.
Example:
The text was updated successfully, but these errors were encountered: