Skip to content

Commit

Permalink
mergeIncludes and mergeQuery allows scope override
Browse files Browse the repository at this point in the history
see discussion in loopbackio#787
  • Loading branch information
ebarault committed Apr 12, 2016
1 parent 1e8fe6a commit 3c0883d
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 3c0883d

Please sign in to comment.