From eb010aedea44e414fbc4c853837beaeefa463b98 Mon Sep 17 00:00:00 2001 From: Mootaz Dinana Date: Fri, 28 Oct 2016 00:29:55 +0200 Subject: [PATCH 1/2] Fix aggregate options ignored in where If aggregate options are passed to where, they are saved to the criteria object from normalize.criteria(criteria) however only criteria.where is saved to _criteria.where, options saved to criteria object is ignored. --- lib/waterline/query/deferred.js | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/lib/waterline/query/deferred.js b/lib/waterline/query/deferred.js index b795e3228..c36da2385 100644 --- a/lib/waterline/query/deferred.js +++ b/lib/waterline/query/deferred.js @@ -338,17 +338,19 @@ Deferred.prototype.where = function(criteria) { this._criteria = false; } - if (!criteria || !criteria.where) return this; + if (!criteria /*|| !criteria.where*/) return this; if (!this._criteria) this._criteria = {}; - var where = this._criteria.where || {}; + // var where = this._criteria.where || {}; - // Merge with existing WHERE clause - Object.keys(criteria.where).forEach(function(key) { - where[key] = criteria.where[key]; - }); + // // Merge with existing WHERE clause + // Object.keys(criteria.where).forEach(function(key) { + // where[key] = criteria.where[key]; + // }); + + // this._criteria.where = where; - this._criteria.where = where; + _.extend(this._criteria, criteria); return this; }; From cd146e4d138792c1c61ff0d8a6754425f6f0c770 Mon Sep 17 00:00:00 2001 From: Mootaz Dinana Date: Fri, 28 Oct 2016 04:37:12 +0200 Subject: [PATCH 2/2] Use _.merge instead of _.extend Use _.merge instead of _.extend to avoid overwriting prev. where criteria --- lib/waterline/query/deferred.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/waterline/query/deferred.js b/lib/waterline/query/deferred.js index c36da2385..344913c26 100644 --- a/lib/waterline/query/deferred.js +++ b/lib/waterline/query/deferred.js @@ -350,7 +350,7 @@ Deferred.prototype.where = function(criteria) { // this._criteria.where = where; - _.extend(this._criteria, criteria); + _.merge(this._criteria, criteria); return this; };