Permalink
Browse files

refactor

  • Loading branch information...
1 parent fbb461c commit 179c3f33e5147b0c8a5715b108a23c012f89ba53 @aheckmann aheckmann committed Oct 12, 2011
Showing with 7 additions and 2 deletions.
  1. +7 −2 lib/model.js
View
@@ -194,15 +194,20 @@ Model.prototype.init = function init (doc, query, fn) {
var i = keys[len]
, path = prefix + i
, schema = self.schema.path(path)
- , poppath = utils.clone(populate[path])//in execution context this parametes is changed and became inconsistent
, total = 0
+ , poppath
if (!schema && obj[i] && 'Object' === obj[i].constructor.name) {
// assume nested object
return init(obj[i], path + '.', next);
}
- if (!(obj[i] && schema && poppath)) return next();
+ if (!(obj[i] && schema && populate[path])) return next();
+
+ // this query object is re-used and passed around. we clone
+ // it to prevent query condition contamination between
+ // one populate call to the next.
+ poppath = utils.clone(populate[path]);
if (poppath.sub) {
obj[i].forEach(function (subobj) {

0 comments on commit 179c3f3

Please sign in to comment.