Sunday, 18 August 2013

Firebase query can return null sibling when there really is another sibling

Firebase query can return null sibling when there really is another sibling

When a limit is applied to a query, the first found element in the query
will have a null previous sibling. Even though it really does have a
sibling, it just hasn't been fetched in the query.
FQuery* messageListQuery = [m_firebaseRef queryLimitedToNumberOfChildren:2];
[messageListQuery observeEventType:FEventTypeChildAdded
andPreviousSiblingNameWithBlock:^(FDataSnapshot *snapshot, NSString
*prevNodeName) {
NSString *nodeName = snapshot.name;
NSDictionary *msgData = snapshot.value;
NSString *where = (prevNodeName == nil) ? @"at the beginning" :
[NSString stringWithFormat:@"after %@", prevNodeName];
NSLog(@"%@ says %@ %@", nodeName, msgData[@"text"], where);
}];
I have 3 messages at the given FirebaseRef. However, it shows that the
Test 2 message has no previous sibling:
-J1JTkEzsdxHGMBEk5eD says Test 2 at the beginning
-J1JW0vpWBZema9QKUcB says Test 3 after -J1JTkEzsdxHGMBEk5eD
When showing all the messages it can be clearly seen Test 2 as a previous
sibling:
-J1JTWoAw5IiUpzkOV4l says Test at the beginning
-J1JTkEzsdxHGMBEk5eD says Test 2 after -J1JTWoAw5IiUpzkOV4l
-J1JW0vpWBZema9QKUcB says Test 3 after -J1JTkEzsdxHGMBEk5eD
I'm not sure if this is a bug or is as designed by Firebase. It seems a
little misleading as one would want to know if there are more nodes by
looking at the prevNodeName parameter.

No comments:

Post a Comment