Skip to content

Commit

Permalink
fix(document): support calling populate() on nested document props
Browse files Browse the repository at this point in the history
Fix #5703
  • Loading branch information
vkarpov15 committed Nov 19, 2017
1 parent 07d8edb commit 6535373
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
10 changes: 9 additions & 1 deletion lib/document.js
Original file line number Diff line number Diff line change
Expand Up @@ -2481,7 +2481,15 @@ Document.prototype.populate = function populate() {
var paths = utils.object.vals(pop);
this.$__.populate = undefined;
paths.__noPromise = true;
this.constructor.populate(this, paths, fn);
var topLevelModel = this.constructor;
if (this.$__isNested) {
topLevelModel = this.$__.scope.constructor;
var nestedPath = this.$__.nestedPath;
paths.forEach(function(populateOptions) {
populateOptions.path = nestedPath + '.' + populateOptions.path;
});
}
topLevelModel.populate(this, paths, fn);
}

return this;
Expand Down
1 change: 1 addition & 0 deletions lib/services/document/compile.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ function defineKey(prop, subprops, prototype, prefix, keys, options) {
if (!prefix) {
nested.$__.scope = this;
}
nested.$__.nestedPath = path;

Object.defineProperty(nested, 'schema', {
enumerable: false,
Expand Down

0 comments on commit 6535373

Please sign in to comment.