Skip to content

Commit 012ba4c

Browse files
authored
feat: Add support for excluding keys in ParseQuery.findAll (#2000)
1 parent 54efcf5 commit 012ba4c

File tree

3 files changed

+22
-6
lines changed

3 files changed

+22
-6
lines changed

integration/test/ParseQueryTest.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1621,6 +1621,23 @@ describe('Parse Query', () => {
16211621
assert.equal(result.get('slice'), 'pizza');
16221622
});
16231623

1624+
it('can exclude keys in findAll', async () => {
1625+
const object = new TestObject({
1626+
hello: 'world',
1627+
foo: 'bar',
1628+
slice: 'pizza',
1629+
});
1630+
await object.save();
1631+
1632+
const query = new Parse.Query(TestObject);
1633+
query.exclude('foo');
1634+
query.equalTo('objectId', object.id);
1635+
const [result] = await query.findAll();
1636+
assert.equal(result.get('foo'), undefined);
1637+
assert.equal(result.get('hello'), 'world');
1638+
assert.equal(result.get('slice'), 'pizza');
1639+
});
1640+
16241641
it('uses subclasses when creating objects', done => {
16251642
const ParentObject = Parse.Object.extend({ className: 'ParentObject' });
16261643
let ChildObject = Parse.Object.extend('ChildObject', {

src/ParseQuery.js

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -948,13 +948,10 @@ class ParseQuery {
948948

949949
const query = new ParseQuery(this.className);
950950
query._limit = options.batchSize || 100;
951-
query._include = this._include.map(i => {
952-
return i;
953-
});
951+
query._include = [...this._include];
952+
query._exclude = [...this._exclude];
954953
if (this._select) {
955-
query._select = this._select.map(s => {
956-
return s;
957-
});
954+
query._select = [...this._select];
958955
}
959956
query._hint = this._hint;
960957
query._where = {};

src/__tests__/ParseQuery-test.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1814,6 +1814,7 @@ describe('ParseQuery', () => {
18141814
q.select('size', 'name');
18151815
q.includeAll();
18161816
q.hint('_id_');
1817+
q.exclude('foo')
18171818

18181819
await q.findAll();
18191820
expect(findMock).toHaveBeenCalledTimes(1);
@@ -1824,6 +1825,7 @@ describe('ParseQuery', () => {
18241825
order: 'objectId',
18251826
keys: 'size,name',
18261827
include: '*',
1828+
excludeKeys: 'foo',
18271829
hint: '_id_',
18281830
where: {
18291831
size: {

0 commit comments

Comments
 (0)