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

execPopulate on virtuals is not working #5240

Closed
SBRK opened this issue May 11, 2017 · 4 comments
Closed

execPopulate on virtuals is not working #5240

SBRK opened this issue May 11, 2017 · 4 comments
Milestone

Comments

@SBRK
Copy link

SBRK commented May 11, 2017

I am trying to use virtual populates as explained in this post: http://thecodebarbarian.com/mongoose-virtual-populate

When using populate with find, there is no problem. However, populating afterwards on a document does not seem to be working

ex:

SomeModelSchema.virtual('bar', {
  ref: 'OtherModel',
  localField: 'otherModelId',
  foreignField: 'id',
  justOne: true,
});

SomeOtherModelSchema = new Schema({
  foo: [SomeModelSchema]
})

// This works, result.foo[0].bar is an OtherModel document
let result = await SomeOtherModel.findOne({}).populate('foo.bar');

// This does not work, result.foo[0].bar is null
result = await SomeOtherModel.findOne({});
result = await result.populate('foo.bar').execPopulate();
@vkarpov15 vkarpov15 added this to the 4.9.10 milestone May 15, 2017
@vkarpov15
Copy link
Collaborator

Thanks for reporting, will fix for next minor release 👍

@vkarpov15 vkarpov15 modified the milestones: 4.9.11, 4.9.10 May 18, 2017
vkarpov15 added a commit that referenced this issue May 21, 2017
@SBRK
Copy link
Author

SBRK commented May 23, 2017

It seems this brought a regression. I have virtual populates not being populated correctly now. I'll investigate to see what's happening exactly

@SBRK
Copy link
Author

SBRK commented May 23, 2017

Yep, populate with execPopulate was broken on nested documents, now it is broken on the first level. 4.10.0 is good, 4.10.1 isn't

SomeModelSchema.virtual('bar', {
  ref: 'OtherModel',
  localField: 'otherModelId',
  foreignField: 'id',
});

// This works, result.bar[0] is an OtherModel document
let result = await SomeModel.findOne({}).populate('bar');

// This does not work, result.bar is null
result = await SomeModel.findOne({});
result = await result.populate('bar').execPopulate();

Got any idea @vkarpov15 ?

@vkarpov15
Copy link
Collaborator

@SBRK opened up a separate issue #5311 ☝️ to track

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