Permalink
Browse files

adding possibility to pass with callback only

  • Loading branch information...
1 parent ff4c1ae commit 43e4ae04e8885b7974d8cfa05d965be8ffbda324 @mariuskubilius committed Jan 14, 2013
Showing with 18 additions and 6 deletions.
  1. +18 −6 lib/ancestorTree.js
View
@@ -88,20 +88,32 @@ ancestorTree = function(schema){
});
schema.method('findDirectChildren', function(opts, cb) {
+ if(arguments.length === 1 && typeof arguments[0] === 'function'){
+ cb = opts;
+ opts = {};
+ }
opts = opts || {};
fields = opts.fields || {title: 1, slug: 1};
return this.model(this.constructor.modelName).find({parent: this._id}, fields, cb);
});
- schema.method('findChildren', function(options, cb) {
- options = options || {};
- fields = options.fields || {title: 1, slug: 1};
+ schema.method('findChildren', function(opts, cb) {
+ if(arguments.length === 1 && typeof arguments[0] === 'function'){
+ cb = opts;
+ opts = {};
+ }
+ opts = opts || {};
+ fields = opts.fields || {title: 1, slug: 1};
return this.model(this.constructor.modelName).find({ancestors: this._id}, fields, cb);
});
- schema.method('getAncestors', function(options, cb) {
- options = options || {};
- fields = options.fields || {title: 1, slug: 1};
+ schema.method('getAncestors', function(opts, cb) {
+ if(arguments.length === 1 && typeof arguments[0] === 'function'){
+ cb = opts;
+ opts = {};
+ }
+ opts = opts || {};
+ fields = opts.fields || {title: 1, slug: 1};
return this.model(this.constructor.modelName).find({_id: {$in: this.ancestors}}, fields, cb);
});

0 comments on commit 43e4ae0

Please sign in to comment.