Skip to content

Commit

Permalink
Should allow an equalTo query with a 'null' value so that the client …
Browse files Browse the repository at this point in the history
…is able to query for data that does not have a specific key.
  • Loading branch information
johnlim committed Oct 25, 2016
1 parent 35e35a1 commit 41b4939
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
14 changes: 9 additions & 5 deletions firebase-query.html
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
*/
query: {
type: Object,
computed: '__computeQuery(ref, orderByChild, orderByValue, limitToFirst, limitToLast, startAt, endAt, equalTo)',
computed: '__computeQuery(ref, orderByChild, orderByValue, limitToFirst, limitToLast, startAt, endAt, equalTo, equalToNull)',
observer: '__queryChanged'
},

Expand Down Expand Up @@ -127,7 +127,11 @@
type: Object,
value: null
},

equalToNull: {
type: Boolean,
reflectToAttribute: true,
value: false
},
/**
* The maximum number of nodes to include in the query.
*
Expand Down Expand Up @@ -240,7 +244,7 @@
}
},

__computeQuery: function(ref, orderByChild, orderByValue, limitToFirst, limitToLast, startAt, endAt, equalTo) {
__computeQuery: function(ref, orderByChild, orderByValue, limitToFirst, limitToLast, startAt, endAt, equalTo, equalToNull) {
if (ref == null) {
return null;
}
Expand Down Expand Up @@ -269,7 +273,7 @@
query = query.endAt(endAt);
}

if (equalTo !== null) {
if (equalTo !== null || equalToNull) {
query = query.equalTo(equalTo);
}

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

this._log('Firebase child_moved:', key, value,
'to index', targetIndex);
'to index', targetIndex);

if (value) {
var index = this.__indexFromKey(key);
Expand Down
15 changes: 15 additions & 0 deletions test/firebase-query.html
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,21 @@
expect(query.data.length).to.be.eql(2);
});
});

test('should allow an equalTo query with a `null` value to enable query for data without a specific key', function() {
query.orderByChild = 'thing';
query.equalTo = null;
query.equalToNull = true;

return setFirebaseValue(query.path, {
a: {thing: true},
b: {thing: false},
c: {nothing: false}
}).then(function() {
expect(query.data[0].$key).to.be.eql('c');
expect(query.data.length).to.be.eql(1);
});
});
});

suite('instance isolation', function() {
Expand Down

0 comments on commit 41b4939

Please sign in to comment.