Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Update count method to handle params like findAll #267

Merged
merged 1 commit into from

2 participants

@tedkulp

No description provided.

@mikermcneil mikermcneil merged commit 8402d1d into balderdashy:master
@mikermcneil
Owner

Thanks Ted, sorry it took me so long to get to this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Mar 26, 2013
  1. @tedkulp
This page is out of date. Refresh to see the latest.
Showing with 21 additions and 4 deletions.
  1. +21 −4 lib/waterline/collection.js
View
25 lib/waterline/collection.js
@@ -409,14 +409,31 @@ function Collection (definition, adapter, cb) {
} else if(_.isFunction(options)) {
cb = options;
options = null;
- } else if(_.isObject(options)) {
+ }
+
+ // Normalize criteria and fold in options
+ criteria = normalize.criteria(criteria);
+ if(_.isObject(options) && _.isObject(criteria)) {
criteria = _.extend({}, criteria, options);
- } else return usageError('Invalid options specified!', usage, cb);
+ }
- if(!_.isFunction(cb)) return usageError('Invalid callback specified!', usage, cb);
+ if(_.isFunction(criteria) || _.isFunction(options)) {
+ return usageError('Invalid options specified!', usage, cb);
+ }
+ // If no callback specified, return deferred object
+ if(!_.isFunction(cb)) {
+ return new Deferred({
+ method: 'count',
+ collection: this,
+ args: {
+ criteria: criteria
+ },
+ argsKeys: ['criteria']
+ });
+ }
// Build model(s) from result set
- return adapter.count(this.identity, criteria, buildModel(this, cb));
+ else return adapter.count(this.identity, criteria, cb);
};
this.countAll = this.count;
Something went wrong with that request. Please try again.