Skip to content
Open
Show file tree
Hide file tree
Changes from 4 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
10 changes: 9 additions & 1 deletion src/ParseQuery.js
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,11 @@ class ParseQuery {
*/
_addCondition(key: string, condition: string, value: mixed): ParseQuery {
if (!this._where[key] || typeof this._where[key] === 'string') {
const prev = this._where[key];
this._where[key] = {};
if (typeof this._where[key] === 'string') {
this._where[key]['$eq'] = prev;
}
}
this._where[key][condition] = encode(value, false, true);
return this;
Expand Down Expand Up @@ -1222,7 +1226,11 @@ class ParseQuery {
return this.doesNotExist(key);
}

this._where[key] = encode(value, false, true);
if (typeof this._where[key] === 'undefined') {
this._where[key] = encode(value, false, true);
} else {
this._addCondition(key, '$eq', value);
}
return this;
}

Expand Down
30 changes: 30 additions & 0 deletions src/__tests__/ParseQuery-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -807,6 +807,36 @@ describe('ParseQuery', () => {
});
});

it('can combine other clauses with equalTo', () => {
const q = new ParseQuery('Item');
q.exists('inStock');
q.equalTo('inStock', null);

expect(q.toJSON()).toEqual({
where: {
inStock: {
$eq: null,
$exists: true,
},
},
});
});

it('can combine equalTo clause with any other clause', () => {
const q = new ParseQuery('Item');
q.equalTo('inStock', null);
q.exists('inStock');

expect(q.toJSON()).toEqual({
where: {
inStock: {
$eq: null,
$exists: true,
},
},
});
});

it('can specify ordering', () => {
const q = new ParseQuery('Item');
q.greaterThan('inStock', 0).ascending('createdAt');
Expand Down