Skip to content

Commit

Permalink
fix: only allow using minus path to remove auto-selected discriminato…
Browse files Browse the repository at this point in the history
…rKey from projection

Re: #11546
  • Loading branch information
vkarpov15 committed Apr 20, 2022
1 parent 5194756 commit 6ab6a33
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
6 changes: 4 additions & 2 deletions lib/queryhelpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -265,8 +265,10 @@ exports.applyPaths = function applyPaths(fields, schema) {
return;
}

// If set to 0, we're excluding a selected path. See gh-11546
if (exclude && type.selected && fields[path] != null && !fields[path]) {
// If set to 0, we're explicitly excluding the discriminator key. Can't do this for all fields,
// because we have tests that assert that using `-path` to exclude schema-level `select: true`
// fields counts as an exclusive projection. See gh-11546
if (exclude && type.selected && path === schema.options.discriminatorKey && fields[path] != null && !fields[path]) {
delete fields[path];
return;
}
Expand Down
2 changes: 1 addition & 1 deletion test/model.discriminator.querying.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ describe('model', function() {
});

describe('findOne', function() {
it('when selecting `select: false` field (gh-4629)', async function() {
it('when selecting `select: false` field (gh-4629) (gh-11546)', async function() {
const s = new SecretEvent({ name: 'test', secret: 'test2' });
await s.save();

Expand Down

0 comments on commit 6ab6a33

Please sign in to comment.