Skip to content

Commit

Permalink
fix(populate): handle nested array foreignField with virtual populate
Browse files Browse the repository at this point in the history
Fix #7374
  • Loading branch information
vkarpov15 committed Jan 17, 2019
1 parent be881e7 commit f424fe4
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
1 change: 1 addition & 0 deletions lib/model.js
Expand Up @@ -3863,6 +3863,7 @@ function populate(model, docs, options, callback) {
for (const foreignField of mod.foreignField) {
_val = utils.getValue(foreignField, val);
if (Array.isArray(_val)) {
_val = utils.array.flatten(_val);
const _valLength = _val.length;
for (let j = 0; j < _valLength; ++j) {
let __val = _val[j];
Expand Down
4 changes: 2 additions & 2 deletions test/model.populate.test.js
Expand Up @@ -8066,12 +8066,12 @@ describe('model: populate:', function() {
const Artist = db.model('gh7374_Artist', artistSchema);

return co(function*() {
const artists = yield Artist.create([
yield Artist.create([
{ _id: 1, name: 'Axl Rose' },
{ _id: 2, name: 'Slash' }
]);

const song = yield Song.create({
yield Song.create({
title: 'November Rain',
identifiers: [{ artists: [{ artist: 1 }, { artist: 2 }] }]
});
Expand Down

0 comments on commit f424fe4

Please sign in to comment.