Skip to content

Commit

Permalink
test(populate): repro #9359
Browse files Browse the repository at this point in the history
  • Loading branch information
vkarpov15 committed Aug 30, 2020
1 parent 9c76bac commit 63a0a46
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions test/types.map.test.js
Expand Up @@ -434,6 +434,42 @@ describe('Map', function() {
assert.equal(event.scenes.get('bar').name, 'bar');
});
});

it('handles populating path of subdoc (gh-9359)', function() {
const bookSchema = Schema({
author: {
type: 'ObjectId',
ref: 'Person'
},
title: String
}, { _id: false });

const schema = Schema({
books: {
type: Map,
of: bookSchema
}
});

const Person = db.model('Person', Schema({ name: String }));
const Test = db.model('Test', schema);

return co(function*() {
const person = yield Person.create({ name: 'Ian Fleming' });
yield Test.create({
books: {
key1: {
title: 'Casino Royale',
author: person._id
}
}
});

const doc = yield Test.findOne().populate('books.$*.author');

assert.equal(doc.books.get('key1').author.name, 'Ian Fleming');
});
});
});

it('discriminators', function() {
Expand Down

0 comments on commit 63a0a46

Please sign in to comment.