Skip to content

fix(ParseQuery): Select on null fields #1223

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Sep 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions integration/test/ParseQueryTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -2024,4 +2024,19 @@ describe('Parse Query', () => {
const explain = await query.find();
assert.equal(explain.queryPlanner.winningPlan.inputStage.inputStage.indexName, '_id_');
});

it('can query with select on null field', async () => {
const obj1 = new TestObject({ number: 1, arrayField: [] });
const obj2 = new TestObject({ number: 2, arrayField: [{ subfield: 1 }] });
const obj3 = new TestObject({ number: 3, arrayField: null });
await Parse.Object.saveAll([obj1, obj2, obj3]);

const query = new Parse.Query(TestObject);
query.select(['arrayField.subfield']);
query.ascending('number');
const results = await query.find();
expect(results[0].get('arrayField')).toEqual([]);
expect(results[1].get('arrayField')).toEqual([{ subfield: 1 }]);
expect(results[2].get('arrayField')).toEqual(null);
});
});
2 changes: 1 addition & 1 deletion src/ParseQuery.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ function handleSelectResult(data: any, select: Array<string>){
if (obj && !obj.hasOwnProperty(component)) {
obj[component] = undefined;
}
if (obj !== undefined) {
if (obj && typeof obj === 'object') {
obj = obj[component];
}

Expand Down