Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Should allow an equalTo query with a 'null' value so that the client … #136

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
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