Skip to content

Commit

Permalink
Fix #2628: tweak sketchy distinct() API
Browse files Browse the repository at this point in the history
  • Loading branch information
vkarpov15 committed Jan 29, 2015
1 parent d2ccf20 commit 37c2797
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 24 deletions.
2 changes: 1 addition & 1 deletion lib/model.js
Original file line number Diff line number Diff line change
Expand Up @@ -1200,7 +1200,7 @@ Model.distinct = function distinct (field, conditions, callback) {
conditions = {};
}

return mq.distinct(conditions, field, callback);
return mq.distinct(field, conditions, callback);
};

/**
Expand Down
30 changes: 7 additions & 23 deletions lib/query.js
Original file line number Diff line number Diff line change
Expand Up @@ -1283,11 +1283,11 @@ Query.prototype.count = function (conditions, callback) {
*
* ####Example
*
* distinct(criteria, field, fn)
* distinct(criteria, field)
* distinct(field, fn)
* distinct(field, conditions, callback)
* distinct(field, conditions)
* distinct(field, callback)
* distinct(field)
* distinct(fn)
* distinct(callback)
* distinct()
*
* @param {Object|Query} [criteria]
Expand All @@ -1298,26 +1298,10 @@ Query.prototype.count = function (conditions, callback) {
* @api public
*/

Query.prototype.distinct = function (conditions, field, callback) {
Query.prototype.distinct = function (field, conditions, callback) {
if (!callback) {
if('function' == typeof field) {
callback = field;
if ('string' == typeof conditions) {
field = conditions;
conditions = undefined;
}
}

switch (typeof conditions) {
case 'string':
field = conditions;
conditions = undefined;
break;
case 'function':
callback = conditions;
field = undefined;
conditions = undefined;
break;
if ('function' == typeof conditions) {
callback = conditions;
}
}

Expand Down

0 comments on commit 37c2797

Please sign in to comment.