Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

adding static access methods to ancestor tree

  • Loading branch information...
commit 8056d90fe48ed33a8280f129a49b18903cb1b512 1 parent 3e78804
@mariuskubilius authored
Showing with 20 additions and 0 deletions.
  1. +20 −0 lib/ancestorTree.js
View
20 lib/ancestorTree.js
@@ -85,5 +85,25 @@ ancestorTree = function(schema){
}
});
}
+/**
+ * @todo write tests for statics.
+ */
+ancestorTree.statics = {
+ findDirectChildren: function(options, cb){
+ options = options || {};
+ fields = options.fields || {title: 1, slug: 1};
+ this.find({parent: this._id}, fields, cb);
+ },
+ findChildren: function(options, cb){
+ options = options || {};
+ fields = options.fields || {title: 1, slug: 1};
+ this.find({hierarchy: this._id}, fields, cb);
+ },
+ getHierarchy: function(options, cb){
+ options = options || {};
+ fields = options.fields || {title: 1, slug: 1};
+ this.find({$in:{_id: this.ancestors}}, fields, cb);
+ }
+};
module.exports = ancestorTree;
Please sign in to comment.
Something went wrong with that request. Please try again.