Skip to content

Commit

Permalink
added; support Model.count(fn)
Browse files Browse the repository at this point in the history
  • Loading branch information
aheckmann committed Sep 2, 2011
1 parent 574529a commit 937f1b4
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
3 changes: 3 additions & 0 deletions lib/model.js
Original file line number Diff line number Diff line change
Expand Up @@ -719,6 +719,9 @@ Model.findOne = function findOne (conditions, fields, options, callback) {
*/

Model.count = function count (conditions, callback) {
if ('function' === typeof conditions)
callback = conditions, conditions = {};

var query = new Query(conditions).bind(this, 'count');
if ('undefined' == typeof callback)
return query;
Expand Down
5 changes: 4 additions & 1 deletion test/model.querying.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,13 +176,16 @@ module.exports = {

'test that count Query executes when you pass a callback': function () {
var db = start()
, BlogPostB = db.model('BlogPostB', collection);
, BlogPostB = db.model('BlogPostB', collection)
, pending = 2

function fn () {
if (--pending) return;
db.close();
};

BlogPostB.count({}, fn).should.be.an.instanceof(Query);
BlogPostB.count(fn).should.be.an.instanceof(Query);
},

'test that distinct returns a Query': function () {
Expand Down

0 comments on commit 937f1b4

Please sign in to comment.