Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Populate can bail out too early if empty array in the field being populated #1055

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 8 additions & 7 deletions lib/model.js
@@ -1,4 +1,3 @@

/*!
* Module dependencies.
*/
Expand Down Expand Up @@ -242,12 +241,14 @@ Model.prototype.init = function init (doc, query, fn) {
if (subobj[key]) (function (key) {

total++;
self._populate(schema.schema.path(key), subobj[key], poppath.sub[key], done);
function done (err, doc) {
if (err) return error(err);
subobj[key] = doc;
--total || next();
}
process.nextTick(function() {
self._populate(schema.schema.path(key), subobj[key], poppath.sub[key], done);
function done (err, doc) {
if (err) return error(err);
subobj[key] = doc;
--total || next();
}
});
})(key);
}
});
Expand Down