Skip to content

Commit 498feba

Browse files
committed
Merge branch 'release/1.3.1'
2 parents 95c6799 + 7c98aee commit 498feba

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

lib/tree.js

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -197,10 +197,17 @@ function tree(schema, options) {
197197
recursive = recursive || false;
198198

199199
if (recursive) {
200-
filters['path'] = {$regex: '^' + this.path + pathSeparator}
201-
}
202-
else {
203-
filters['parent'] = this._id
200+
if(filters['$query']){
201+
filters['$query']['path'] = {$regex: '^' + this.path + pathSeparator};
202+
} else {
203+
filters['path'] = {$regex: '^' + this.path + pathSeparator};
204+
}
205+
} else {
206+
if(filters['$query']){
207+
filters['$query']['parent'] = this._id;
208+
} else {
209+
filters['parent'] = this._id;
210+
}
204211
}
205212

206213
return this.model(this.constructor.modelName).find(filters, fields, options, next);
@@ -252,7 +259,11 @@ function tree(schema, options) {
252259
ids.pop();
253260
}
254261

255-
filters['_id'] = {$in: ids};
262+
if(filters['$query']){
263+
filters['$query']['_id'] = {$in: ids};
264+
} else {
265+
filters['_id'] = {$in: ids};
266+
}
256267

257268
return this.model(this.constructor.modelName).find(filters, fields, options, next);
258269
};

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"url": "git://github.com/swayf/mongoose-path-tree.git"
1717
},
1818
"main": "index.js",
19-
"version": "1.2.1",
19+
"version": "1.3.1",
2020
"engine": "node >= 0.4.0",
2121
"dependencies": {
2222
"mongoose": "3.x.x",

0 commit comments

Comments
 (0)