Skip to content

Commit 3f8a1aa

Browse files
committed
Merge pull request #1250 from andrecardoso/live-query-server-matching-does-not-exist-queries
Matching queries with doesNotExist constraint
2 parents 6479875 + 3dccd61 commit 3f8a1aa

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

spec/QueryTools.spec.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,20 @@ describe('matchesQuery', function() {
112112
expect(matchesQuery(obj, q)).toBe(false);
113113
});
114114

115+
it('matches queries with doesNotExist constraint', function() {
116+
var obj = {
117+
id: new Id('Item', 'O1'),
118+
count: 15
119+
};
120+
var q = new Parse.Query('Item');
121+
q.doesNotExist('name');
122+
expect(matchesQuery(obj, q)).toBe(true);
123+
124+
q = new Parse.Query('Item');
125+
q.doesNotExist('count');
126+
expect(matchesQuery(obj, q)).toBe(false);
127+
});
128+
115129
it('matches on equality queries', function() {
116130
var day = new Date();
117131
var location = new Parse.GeoPoint({

src/LiveQuery/QueryTools.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,9 @@ function matchesKeyConstraints(object, key, constraints) {
206206
}
207207
break;
208208
case '$exists':
209-
if (typeof object[key] === 'undefined') {
209+
let propertyExists = typeof object[key] !== 'undefined';
210+
let existenceIsRequired = constraints['$exists'];
211+
if ((!propertyExists && existenceIsRequired) || (propertyExists && !existenceIsRequired)) {
210212
return false;
211213
}
212214
break;

0 commit comments

Comments
 (0)