Reputation: 2057
I'm try to join three data using Firebase. I want to retrieve the the school name
querying to classes
data knowing only guard key which is g1
. I know it can be done in two separate calls, but I'm trying to do it in just one call to the server.
Is it somewhat possible?
Schools
schools :
schoolKey1 :
name: School One
schoolKey2 :
name: School Two
Classes
classes :
someKey1 :
name: Class One
school : schoolKey1
guard : g1
Guard
guards :
g1 :
name: Pipoy Pat
Upvotes: 1
Views: 5679
Reputation: 159
It might be too late but you would need to follow the documentation here.
something like:
var ref = new Firebase("https://myApp.firebaseio.com/");
// fetch classes
ref.child("classes").addChildEventListener(new ChildEventListener() {
@Override
public void onChildAdded(DataSnapshot snapshot, String previousChildKey) {
//get school key
String schoolKey = snapshot.getKey();
//get school name from key
ref.child("schools/" + schoolKey + "/name").addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot snapshot) {
System.out.println("The school name is " + snapshot.getValue());
}
@Override
public void onCancelled(FirebaseError firebaseError) {
// ignore for now
}
});
}
});
Upvotes: 3