Permalink
Browse files

adding static access methods to ancestor tree

  • Loading branch information...
1 parent 3e78804 commit 8056d90fe48ed33a8280f129a49b18903cb1b512 @mariuskubilius committed Jan 10, 2013
Showing with 20 additions and 0 deletions.
  1. +20 −0 lib/ancestorTree.js
View
@@ -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;

0 comments on commit 8056d90

Please sign in to comment.