Skip to content

Commit 77c543d

Browse files
authored
Accept multiple paths or array of paths to depopulate
- `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
1 parent 3771f49 commit 77c543d

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

lib/document.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2592,12 +2592,17 @@ Document.prototype.populated = function(path, val, options) {
25922592
*/
25932593

25942594
Document.prototype.depopulate = function(path) {
2595-
var populatedIds = this.populated(path);
2596-
if (!populatedIds) {
2597-
return;
2595+
if (typeof path === 'string') {
2596+
path = path.split(' ');
2597+
}
2598+
for (const p of path) {
2599+
var populatedIds = this.populated(p);
2600+
if (!populatedIds) {
2601+
continue;
2602+
}
2603+
delete this.$__.populated[p];
2604+
this.$set(p, populatedIds);
25982605
}
2599-
delete this.$__.populated[path];
2600-
this.$set(path, populatedIds);
26012606
return this;
26022607
};
26032608

0 commit comments

Comments
 (0)