Skip to content

Commit

Permalink
fix(populate): correctly get schema type underneath map of mixed in g…
Browse files Browse the repository at this point in the history
…etSchemaTypes
  • Loading branch information
vkarpov15 committed Oct 27, 2022
1 parent 5740c2c commit 0b70933
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/helpers/populate/getSchemaTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,8 @@ module.exports = function getSchemaTypes(model, schema, doc, path) {
}
}
}
} else if (foundschema.$isSchemaMap && foundschema.$__schemaType instanceof Mixed) {
return foundschema.$__schemaType;
}

const fullPath = nestedPath.concat([trypath]).join('.');
Expand Down
14 changes: 14 additions & 0 deletions test/helpers/populate.getSchemaTypes.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,4 +178,18 @@ describe('getSchemaTypes', function() {
assert.equal(schemaTypes.length, 1);
assert.equal(schemaTypes[0].options.ref, 'Enemy');
});

it('finds path underneath nested subdocument with map of mixed (gh-12530)', function() {
const schema = new Schema({
child: new Schema({
testMap: {
type: Map,
of: 'Mixed'
}
})
});

const schemaTypes = getSchemaTypes(null, schema, null, 'child.testMap.foo.bar');
assert.equal(schemaTypes.instance, 'Mixed');
});
});

0 comments on commit 0b70933

Please sign in to comment.