Skip to content

Commit

Permalink
Merge pull request #5798 from adamreisnz/patch-1
Browse files Browse the repository at this point in the history
Accept multiple paths or array of paths to depopulate
  • Loading branch information
vkarpov15 authored Nov 7, 2017
2 parents 060fcdf + 3b07c00 commit 54d9189
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions lib/document.js
Original file line number Diff line number Diff line change
Expand Up @@ -2592,12 +2592,17 @@ Document.prototype.populated = function(path, val, options) {
*/

Document.prototype.depopulate = function(path) {
var populatedIds = this.populated(path);
if (!populatedIds) {
return;
if (typeof path === 'string') {
path = path.split(' ');
}
for (var i = 0; i < path.length; i++) {
var populatedIds = this.populated(path[i]);
if (!populatedIds) {
continue;
}
delete this.$__.populated[path[i]];
this.$set(path[i], populatedIds);
}
delete this.$__.populated[path];
this.$set(path, populatedIds);
return this;
};

Expand Down

0 comments on commit 54d9189

Please sign in to comment.