From 3c0883de2764c137d702295dddb3ead5edc04ff6 Mon Sep 17 00:00:00 2001 From: ebarault Date: Tue, 12 Apr 2016 22:24:36 +0200 Subject: [PATCH] mergeIncludes and mergeQuery allows scope override see discussion in https://github.com/strongloop/loopback-datasource-juggler/pull/787 --- lib/utils.js | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/lib/utils.js b/lib/utils.js index ed2fabfd8..53611ad4a 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -73,7 +73,9 @@ function setScopeValuesFromWhere(data, where, targetModel) { * @param {String|Array|Object} source The runtime value of `include` option * @returns {Object} */ -function mergeIncludes(destination, source) { +// function mergeIncludes(destination, source) { +// NOTE see: https://github.com/strongloop/loopback-datasource-juggler/pull/787 +function mergeIncludes(source, destination) { var destArray = convertToArray(destination); var sourceArray = convertToArray(source); if (destArray.length === 0) { @@ -193,12 +195,20 @@ function mergeQuery(base, update, spec) { } // Overwrite fields - if (spec.fields !== false && update.fields !== undefined) { + // NOTE see: https://github.com/strongloop/loopback-datasource-juggler/pull/787 + if (spec.fields !== false && base.fields === undefined && update.fields !== undefined) { base.fields = update.fields; - } else if (update.fields !== undefined) { + } else if (spec.fields !== false && update.fields !== undefined) { base.fields = [].concat(base.fields).concat(update.fields); } + // // Overwrite fields + // if (spec.fields !== false && update.fields !== undefined) { + // base.fields = update.fields; + // } else if (update.fields !== undefined) { + // base.fields = [].concat(base.fields).concat(update.fields); + // } + // set order if ((!base.order || spec.order === false) && update.order) { base.order = update.order;