From 2a42c4a50d68031cf49e1cbe8931968abad39644 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Wolski?= Date: Sun, 23 Jun 2013 19:40:30 +0200 Subject: [PATCH] Allow multiple calls to order in aggregates --- lib/AggregateFunctions.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/AggregateFunctions.js b/lib/AggregateFunctions.js index 1896aa73..2e02ec26 100644 --- a/lib/AggregateFunctions.js +++ b/lib/AggregateFunctions.js @@ -10,6 +10,7 @@ function AggregateFunctions(opts) { var aggregates = [ [] ]; var group_by = null; + var order_by = opts.order ? [opts.order] : []; var used_distinct = false; var appendFunction = function (fun) { @@ -44,7 +45,7 @@ function AggregateFunctions(opts) { return this; }, order: function (property, order) { - opts.order = [ property, order ]; + order_by.push([ property, order ]); return this; }, select: function () { @@ -92,9 +93,10 @@ function AggregateFunctions(opts) { query.groupBy.apply(query, group_by); } - if (opts.order) { - query.order.apply(query, opts.order); + for(var i = 0; i < order_by.length; i++){ + query.order.apply(query, order_by[i]); } + if (opts.limit) { query.offset(opts.limit[0]).limit(opts.limit[1]); }