Skip to content

Commit

Permalink
Accept multiple paths or array of paths to depopulate
Browse files Browse the repository at this point in the history
- `Document.depopulate()` now accepts an array of paths, e.g. `['some', 'path', 'other.path']`
- `Document.depopulate()` now accepts space separated paths, e.g. `'some path other.path'`
- Fixes #5797
  • Loading branch information
adamreisnz authored Nov 7, 2017
1 parent 3771f49 commit 77c543d
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 (const p of path) {
var populatedIds = this.populated(p);
if (!populatedIds) {
continue;
}
delete this.$__.populated[p];
this.$set(p, populatedIds);
}
delete this.$__.populated[path];
this.$set(path, populatedIds);
return this;
};

Expand Down

0 comments on commit 77c543d

Please sign in to comment.