@@ -365,6 +365,9 @@ DocumentArrayPath.prototype.getDefault = function(scope) {
365
365
return ret ;
366
366
} ;
367
367
368
+ const _toObjectOptions = Object . freeze ( { transform : false , virtuals : false } ) ;
369
+ const initDocumentOptions = Object . freeze ( { skipId : true , willInit : true } ) ;
370
+
368
371
/**
369
372
* Casts contents
370
373
*
@@ -384,7 +387,7 @@ DocumentArrayPath.prototype.cast = function(value, doc, init, prev, options) {
384
387
385
388
let selected ;
386
389
let subdoc ;
387
- const _opts = { transform : false , virtuals : false } ;
390
+
388
391
options = options || { } ;
389
392
390
393
if ( ! Array . isArray ( value ) ) {
@@ -414,9 +417,7 @@ DocumentArrayPath.prototype.cast = function(value, doc, init, prev, options) {
414
417
}
415
418
416
419
const rawArray = utils . isMongooseDocumentArray ( value ) ? value . __array : value ;
417
-
418
420
const len = rawArray . length ;
419
- const initDocumentOptions = { skipId : true , willInit : true } ;
420
421
421
422
for ( let i = 0 ; i < len ; ++ i ) {
422
423
if ( ! rawArray [ i ] ) {
@@ -464,7 +465,7 @@ DocumentArrayPath.prototype.cast = function(value, doc, init, prev, options) {
464
465
subdoc = prev . id ( rawArray [ i ] . _id ) ;
465
466
}
466
467
467
- if ( prev && subdoc && utils . deepEqual ( subdoc . toObject ( _opts ) , rawArray [ i ] ) ) {
468
+ if ( prev && subdoc && utils . deepEqual ( subdoc . toObject ( _toObjectOptions ) , rawArray [ i ] ) ) {
468
469
// handle resetting doc with existing id and same data
469
470
subdoc . set ( rawArray [ i ] ) ;
470
471
// if set() is hooked it will have no return value
0 commit comments