Skip to content

Commit 3c0883d

Browse files
committed
mergeIncludes and mergeQuery allows scope override
see discussion in loopbackio#787
1 parent 1e8fe6a commit 3c0883d

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

lib/utils.js

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,9 @@ function setScopeValuesFromWhere(data, where, targetModel) {
7373
* @param {String|Array|Object} source The runtime value of `include` option
7474
* @returns {Object}
7575
*/
76-
function mergeIncludes(destination, source) {
76+
// function mergeIncludes(destination, source) {
77+
// NOTE see: https://github.com/strongloop/loopback-datasource-juggler/pull/787
78+
function mergeIncludes(source, destination) {
7779
var destArray = convertToArray(destination);
7880
var sourceArray = convertToArray(source);
7981
if (destArray.length === 0) {
@@ -193,12 +195,20 @@ function mergeQuery(base, update, spec) {
193195
}
194196

195197
// Overwrite fields
196-
if (spec.fields !== false && update.fields !== undefined) {
198+
// NOTE see: https://github.com/strongloop/loopback-datasource-juggler/pull/787
199+
if (spec.fields !== false && base.fields === undefined && update.fields !== undefined) {
197200
base.fields = update.fields;
198-
} else if (update.fields !== undefined) {
201+
} else if (spec.fields !== false && update.fields !== undefined) {
199202
base.fields = [].concat(base.fields).concat(update.fields);
200203
}
201204

205+
// // Overwrite fields
206+
// if (spec.fields !== false && update.fields !== undefined) {
207+
// base.fields = update.fields;
208+
// } else if (update.fields !== undefined) {
209+
// base.fields = [].concat(base.fields).concat(update.fields);
210+
// }
211+
202212
// set order
203213
if ((!base.order || spec.order === false) && update.order) {
204214
base.order = update.order;

0 commit comments

Comments
 (0)