Skip to content

Commit

Permalink
fix(schema): also propagate typePojoToMixed option to schemas impli…
Browse files Browse the repository at this point in the history
…citly created because of `typePojoToMixed`

Fix #8627
  • Loading branch information
vkarpov15 committed Mar 7, 2020
1 parent 1cd05dd commit b4b61d3
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,10 @@ Schema.prototype.add = function add(obj, prefix) {
if (prefix) {
this.nested[prefix.substr(0, prefix.length - 1)] = true;
}
const schemaWrappedPath = Object.assign({}, obj[key], { type: new Schema(obj[key][this.options.typeKey]) });
// Propage `typePojoToMixed` to implicitly created schemas
const opts = { typePojoToMixed: false };
const _schema = new Schema(obj[key][this.options.typeKey], opts);
const schemaWrappedPath = Object.assign({}, obj[key], { type: _schema });
this.path(prefix + key, schemaWrappedPath);
} else {
// Either the type is non-POJO or we interpret it as Mixed anyway
Expand Down
17 changes: 17 additions & 0 deletions test/types.embeddeddocumentdeclarative.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,23 @@ describe('types.embeddeddocumentdeclarative', function() {
assert.ok(schema.path('arr').schema.path('nested').instance !== 'Mixed');
assert.ok(schema.path('arr').schema.path('nested.test') instanceof mongoose.Schema.Types.String);
});

it('nested array (gh-8627)', function() {
const schema = new Schema({
l1: {
type: {
l2: {
type: {
test: String
}
}
}
}
}, { typePojoToMixed: false });

assert.ok(schema.path('l1').instance !== 'Mixed');
assert.ok(schema.path('l1.l2').instance !== 'Mixed');
});
});
});
describe('with a parent with a POJO field with a field "type" with a type set to "String"', function() {
Expand Down

0 comments on commit b4b61d3

Please sign in to comment.