Skip to content

Commit

Permalink
Fix setter apply order
Browse files Browse the repository at this point in the history
Apply setter on array of objects before array caster setters
  • Loading branch information
brandom committed Feb 19, 2015
1 parent 968c04a commit 168931f
Showing 1 changed file with 4 additions and 9 deletions.
13 changes: 4 additions & 9 deletions lib/schematype.js
Expand Up @@ -559,21 +559,16 @@ SchemaType.prototype.applySetters = function (value, scope, init, priorVal) {
, len = setters.length
, caster = this.caster;

while (len--) {
v = setters[len].call(scope, v, this);
}

if (Array.isArray(v) && caster && caster.setters) {
for (var i = 0; i < v.length; i++) {
v[i] = caster.applySetters(v[i], scope, init, priorVal);
}
}

if (!len) {
if (null === v || undefined === v) return v;
return this.cast(v, scope, init, priorVal)
}

while (len--) {
v = setters[len].call(scope, v, this);
}

if (null === v || undefined === v) return v;

// do not cast until all setters are applied #665
Expand Down

0 comments on commit 168931f

Please sign in to comment.