From 6973de7910e22225d1e8d20379fa750d74752c67 Mon Sep 17 00:00:00 2001 From: Carmen Date: Thu, 3 Mar 2016 16:15:36 +0800 Subject: [PATCH] Fix replace query overwrite the existing query object. --- src/RestQuery.js | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/src/RestQuery.js b/src/RestQuery.js index e68ec16f..2596344c 100644 --- a/src/RestQuery.js +++ b/src/RestQuery.js @@ -214,7 +214,11 @@ RestQuery.prototype.replaceInQuery = function() { }); } delete inQueryObject['$inQuery']; - inQueryObject['$in'] = values; + if (Array.isArray(inQueryObject['$in'])) { + inQueryObject['$in'] = inQueryObject['$in'].concat(values); + } else { + inQueryObject['$in'] = values; + } // Recurse to repeat return this.replaceInQuery(); @@ -251,7 +255,11 @@ RestQuery.prototype.replaceNotInQuery = function() { }); } delete notInQueryObject['$notInQuery']; - notInQueryObject['$nin'] = values; + if (Array.isArray(notInQueryObject['$nin'])) { + notInQueryObject['$nin'] = notInQueryObject['$nin'].concat(values); + } else { + notInQueryObject['$nin'] = values; + } // Recurse to repeat return this.replaceNotInQuery(); @@ -290,7 +298,11 @@ RestQuery.prototype.replaceSelect = function() { values.push(result[selectValue.key]); } delete selectObject['$select']; - selectObject['$in'] = values; + if (Array.isArray(selectObject['$in'])) { + selectObject['$in'] = selectObject['$in'].concat(values); + } else { + selectObject['$in'] = values; + } // Keep replacing $select clauses return this.replaceSelect(); @@ -329,7 +341,11 @@ RestQuery.prototype.replaceDontSelect = function() { values.push(result[dontSelectValue.key]); } delete dontSelectObject['$dontSelect']; - dontSelectObject['$nin'] = values; + if (Array.isArray(dontSelectObject['$nin'])) { + dontSelectObject['$nin'] = dontSelectObject['$nin'].concat(values); + } else { + dontSelectObject['$nin'] = values; + } // Keep replacing $dontSelect clauses return this.replaceDontSelect();