0
If you want to know what are the groups where the user Z1FZPBz9m0T1yg21DBfRgI2bGFO2
participates, you can do:
Query query = db.child("attendee").orderByChild("userUID").equalTo("Z1FZPBz9m0T1yg21DBfRgI2bGFO2");
query.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot datasnapshot) {
for (snap : datasnapshot) {
String groupUID = snap.getKey();
// Utilizar o groupID
}
}
@Override
public void onCancelled(DatabaseError error) {
}
});
Updating: To access the group object:
Query query = db.child("attendee").orderByChild("userUID").equalTo("Z1FZPBz9m0T1yg21DBfRgI2bGFO2");
query.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot datasnapshot) {
for (snap : datasnapshot) {
String groupUID = snap.getKey();
// Utilizar o groupID para achar o objeto grupo
db.child("group").child(groupUID).addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnap) {
Group group = dataSnap.getValue(Group.class)
//Adicionar o group à lista
}
@Override
public void onCancelled(DatabaseError error) {
}
});
}
}
@Override
public void onCancelled(DatabaseError error) {
}
});
in which case this code would return me the group key, right? What if I need to return the Group object? for each group that the user is part of... because what I need is to add to a list each Group object related to the group that the user participates in
– Xandi Vieira
I updated my reply to show how to access each group object
– Rosário Pereira Fernandes
If in my table "Attendee", in the place of "userUID" I had a list of "userUID". How the query would look to find the groups that user is part of...?
– Xandi Vieira