Skip to content
This repository was archived by the owner on May 19, 2025. It is now read-only.

Commit a97d2e5

Browse files
committed
Should allow an equalTo query with a 'null' value so that the client is able to query for data that does not have a specific key.
1 parent 7b87184 commit a97d2e5

File tree

2 files changed

+24
-5
lines changed

2 files changed

+24
-5
lines changed

firebase-query.html

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@
6969
*/
7070
query: {
7171
type: Object,
72-
computed: '__computeQuery(ref, orderByChild, orderByValue, limitToFirst, limitToLast, startAt, endAt, equalTo)',
72+
computed: '__computeQuery(ref, orderByChild, orderByValue, limitToFirst, limitToLast, startAt, endAt, equalTo, equalToNull)',
7373
observer: '__queryChanged'
7474
},
7575

@@ -127,7 +127,11 @@
127127
type: Object,
128128
value: null
129129
},
130-
130+
equalToNull: {
131+
type: Boolean,
132+
reflectToAttribute: true,
133+
value: false
134+
},
131135
/**
132136
* The maximum number of nodes to include in the query.
133137
*
@@ -240,7 +244,7 @@
240244
}
241245
},
242246

243-
__computeQuery: function(ref, orderByChild, orderByValue, limitToFirst, limitToLast, startAt, endAt, equalTo) {
247+
__computeQuery: function(ref, orderByChild, orderByValue, limitToFirst, limitToLast, startAt, endAt, equalTo, equalToNull) {
244248
if (ref == null) {
245249
return null;
246250
}
@@ -269,7 +273,7 @@
269273
query = query.endAt(endAt);
270274
}
271275

272-
if (equalTo !== null) {
276+
if (equalTo !== null || equalToNull) {
273277
query = query.equalTo(equalTo);
274278
}
275279

@@ -375,7 +379,7 @@
375379
var targetIndex = previousChildKey ? this.__indexFromKey(previousChildKey) : 0;
376380

377381
this._log('Firebase child_moved:', key, value,
378-
'to index', targetIndex);
382+
'to index', targetIndex);
379383

380384
if (value) {
381385
var index = this.__indexFromKey(key);

test/firebase-query.html

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,21 @@
280280
expect(query.data.length).to.be.eql(2);
281281
});
282282
});
283+
284+
test('should allow an equalTo query with a `null` value to enable query for data without a specific key', function() {
285+
query.orderByChild = 'thing';
286+
query.equalTo = null;
287+
query.equalToNull = true;
288+
289+
return setFirebaseValue(query.path, {
290+
a: {thing: true},
291+
b: {thing: false},
292+
c: {nothing: false}
293+
}).then(function() {
294+
expect(query.data[0].$key).to.be.eql('c');
295+
expect(query.data.length).to.be.eql(1);
296+
});
297+
});
283298
});
284299

285300
suite('instance isolation', function() {

0 commit comments

Comments
 (0)