Skip to content

Commit

Permalink
fix(query): don't explicitly project in discriminator key if user pro…
Browse files Browse the repository at this point in the history
…jected in parent path

Fix #5775
  • Loading branch information
vkarpov15 committed Nov 5, 2017
1 parent a12d282 commit 2adf1f3
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions lib/queryhelpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* Module dependencies
*/

var get = require('lodash.get');
var utils = require('./utils');

/*!
Expand Down Expand Up @@ -75,7 +76,6 @@ exports.createModel = function createModel(model, doc, fields, userProvidedField

exports.applyPaths = function applyPaths(fields, schema) {
// determine if query is selecting or excluding fields

var exclude;
var keys;
var ki;
Expand Down Expand Up @@ -123,8 +123,25 @@ exports.applyPaths = function applyPaths(fields, schema) {
}

// check for parent exclusions
var root = path.split('.')[0];
if (~excluded.indexOf(root)) return;
var pieces = path.split('.');
var root = pieces[0];
if (~excluded.indexOf(root)) {
return;
}

// Special case: if user has included a parent path of a discriminator key,
// don't explicitly project in the discriminator key because that will
// project out everything else under the parent path
if (!exclude && get(type, 'options.$skipDiscriminatorCheck', false)) {
var cur = '';
for (var i = 0; i < pieces.length; ++i) {
cur += (cur.length === 0 ? '' : '.') + pieces[i];
var projection = get(fields, cur, false);
if (projection && typeof projection !== 'object') {
return;
}
}
}

(type.selected ? selected : excluded).push(path);
};
Expand Down

0 comments on commit 2adf1f3

Please sign in to comment.