Skip to content

Commit

Permalink
fix(document): don't create a new array subdoc when creating schema a…
Browse files Browse the repository at this point in the history
…rray

Fix #5162
  • Loading branch information
vkarpov15 committed Apr 20, 2017
1 parent d467f05 commit 190374a
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 7 deletions.
2 changes: 1 addition & 1 deletion lib/schema/array.js
Expand Up @@ -63,7 +63,7 @@ function SchemaArray(key, cast, options, schemaOptions) {
: cast;

this.casterConstructor = caster;
if (typeof caster === 'function') {
if (typeof caster === 'function' && !caster.$isArraySubdocument) {
this.caster = new caster(null, castOptions);
} else {
this.caster = caster;
Expand Down
8 changes: 2 additions & 6 deletions lib/types/array.js
Expand Up @@ -119,10 +119,10 @@ MongooseArray.mixin = {
if (!isDisc) {
value = new Model(value);
}
return this._schema.caster.cast(value, this._parent, true);
return this._schema.caster.applySetters(value, this._parent, true);
}

return this._schema.caster.cast(value, this._parent, false);
return this._schema.caster.applySetters(value, this._parent, false);
},

/**
Expand Down Expand Up @@ -698,10 +698,6 @@ MongooseArray.mixin = {

set: function set(i, val) {
var value = this._cast(val, i);
value = this._schema.caster instanceof EmbeddedDocument ?
value :
this._schema.caster.applySetters(val, this._parent)
;
this[i] = value;
this._markModified(i);
return this;
Expand Down

0 comments on commit 190374a

Please sign in to comment.