Skip to content

Commit e2f72c0

Browse files
authored
fix(ParseQuery): Select on null fields (#1223)
* fix(ParseQuery): Select on null fields Closes: #1196 * Add better check
1 parent fa05044 commit e2f72c0

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

integration/test/ParseQueryTest.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2024,4 +2024,19 @@ describe('Parse Query', () => {
20242024
const explain = await query.find();
20252025
assert.equal(explain.queryPlanner.winningPlan.inputStage.inputStage.indexName, '_id_');
20262026
});
2027+
2028+
it('can query with select on null field', async () => {
2029+
const obj1 = new TestObject({ number: 1, arrayField: [] });
2030+
const obj2 = new TestObject({ number: 2, arrayField: [{ subfield: 1 }] });
2031+
const obj3 = new TestObject({ number: 3, arrayField: null });
2032+
await Parse.Object.saveAll([obj1, obj2, obj3]);
2033+
2034+
const query = new Parse.Query(TestObject);
2035+
query.select(['arrayField.subfield']);
2036+
query.ascending('number');
2037+
const results = await query.find();
2038+
expect(results[0].get('arrayField')).toEqual([]);
2039+
expect(results[1].get('arrayField')).toEqual([{ subfield: 1 }]);
2040+
expect(results[2].get('arrayField')).toEqual(null);
2041+
});
20272042
});

src/ParseQuery.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ function handleSelectResult(data: any, select: Array<string>){
9797
if (obj && !obj.hasOwnProperty(component)) {
9898
obj[component] = undefined;
9999
}
100-
if (obj !== undefined) {
100+
if (obj && typeof obj === 'object') {
101101
obj = obj[component];
102102
}
103103

0 commit comments

Comments
 (0)