Skip to content

Commit ab360ff

Browse files
committed
true fix
1 parent fd94cd1 commit ab360ff

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

lib/schema.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,7 @@ Schema.prototype._clone = function _clone(Constructor) {
413413

414414
s.tree = clone(this.tree);
415415
s.paths = Object.fromEntries(
416-
Object.entries(this.paths).map(([key, value]) => ([key, !value.$isMongooseDocumentArray ? value.clone() : value]))
416+
Object.entries(this.paths).map(([key, value]) => ([key, value.clone()]))
417417
);
418418
s.nested = clone(this.nested);
419419
s.subpaths = clone(this.subpaths);

lib/schema/documentarray.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ function DocumentArrayPath(key, schema, options, schemaOptions) {
8989
this.$embeddedSchemaType.caster = this.Constructor;
9090
this.$embeddedSchemaType.schema = this.schema;
9191

92-
if (schema._applyDiscriminators != null) {
92+
if (schema._applyDiscriminators != null && !options?._skipApplyDiscriminators) {
9393
for (const disc of schema._applyDiscriminators.keys()) {
9494
this.discriminator(disc, schema._applyDiscriminators.get(disc));
9595
}
@@ -528,7 +528,7 @@ DocumentArrayPath.prototype.cast = function(value, doc, init, prev, options) {
528528

529529
DocumentArrayPath.prototype.clone = function() {
530530
const options = Object.assign({}, this.options);
531-
const schematype = new this.constructor(this.path, this.schema, options, this.schemaOptions);
531+
const schematype = new this.constructor(this.path, this.schema, { ...options, _skipApplyDiscriminators: true }, this.schemaOptions);
532532
schematype.validators = this.validators.slice();
533533
if (this.requiredValidator !== undefined) {
534534
schematype.requiredValidator = this.requiredValidator;

0 commit comments

Comments
 (0)