From 682f1e3adc244f4ebf95e06e6593e9ff73a4b016 Mon Sep 17 00:00:00 2001 From: Taha Boulehmi Date: Tue, 19 Nov 2019 15:33:25 +0200 Subject: [PATCH 1/2] Fix for selecting specific fields in population for one-to-one relationship If there is a population for a one-to-one relationship, we should accept only "select" and "omit" attributes. --- lib/waterline/utils/query/forge-stage-two-query.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/waterline/utils/query/forge-stage-two-query.js b/lib/waterline/utils/query/forge-stage-two-query.js index 6fd6ea1f6..217a19ba2 100644 --- a/lib/waterline/utils/query/forge-stage-two-query.js +++ b/lib/waterline/utils/query/forge-stage-two-query.js @@ -876,7 +876,7 @@ module.exports = function forgeStageTwoQuery(query, orm) { // Otherwise, this simply must be `true`. Otherwise it's invalid. else { - if (query.populates[populateAttrName] !== true) { + if (query.populates[populateAttrName] !== true && (_.isUndefined(query.populates[populateAttrName].select) && _.isUndefined(query.populates[populateAttrName].omit))) { throw buildUsageError( 'E_INVALID_POPULATES', 'Could not populate `'+populateAttrName+'`. '+ @@ -894,6 +894,12 @@ module.exports = function forgeStageTwoQuery(query, orm) { query.using ); }//-• + else { + query.populates[populateAttrName] = { + select: query.populates[populateAttrName].select? query.populates[populateAttrName].select : undefined, + omit: query.populates[populateAttrName].omit? query.populates[populateAttrName].omit : undefined + }; + } }//>-• From 165371084b71729c792e466952c93c8cd585ee26 Mon Sep 17 00:00:00 2001 From: Taha Boulehmi Date: Tue, 19 Nov 2019 15:58:41 +0200 Subject: [PATCH 2/2] Updating the comment --- lib/waterline/utils/query/forge-stage-two-query.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/waterline/utils/query/forge-stage-two-query.js b/lib/waterline/utils/query/forge-stage-two-query.js index 217a19ba2..ea8653649 100644 --- a/lib/waterline/utils/query/forge-stage-two-query.js +++ b/lib/waterline/utils/query/forge-stage-two-query.js @@ -886,8 +886,7 @@ module.exports = function forgeStageTwoQuery(query, orm) { 'since it generally wouldn\'t make any sense. But that\'s the trouble-- it '+ 'looks like some sort of a subcriteria (or something) _was_ provided!\n'+ '(Note that subcriterias consisting ONLY of `omit` or `select` are a special '+ - 'case that _does_ make sense. This usage will be supported in a future version '+ - 'of Waterline.)\n'+ + 'case that _does_ make sense.\n'+ '\n'+ 'Here\'s what was passed in:\n'+ util.inspect(query.populates[populateAttrName], {depth: 5}),