I have the follow structure in my firebase database:
{
rooms: {
LKVmdIPX2_235ksf: {
members: {
poasj12O-s657-235a-1236-9832lksf976c: true
},
name: Room 1,
public: true
},
KS0sk21gleascm14: {
members: {
poasj12O-s657-235a-1236-9832lksf976c: true
},
name: Room 2,
public: true
}
},
users: {
poasj12O-s657-235a-1236-9832lksf976c: {
rooms: {
LKVmdIPX2_235ksf: true,
KS0sk21gleascm14: true
},
name: Filler
email: filler@filler.com
}
}
In order to get every room from a specific user(in this case the user with = poasj12O-s657-235a-1236-9832lksf976c) I've done the following:
$scope.rooms = {};
var ref = new Firebase('URL');
var userRef = ref.child('users').child(uid); // I'm manage to get the user's UID after login;
var roomRef = ref.child('rooms');
userRef.child('rooms').on('child_added', function(data) {
roomRef.child(data.key()).on('value', function(rData) {
console.log(rData.val()); // prints each room object
$scope.rooms = $firebaseArray(rData.ref());
});
});
So in order to be able to display that info in the view I've tried:
$scope.rooms = $firebaseArray(rData.ref());
The problem is when I do console.log($scope.rooms)
I just get an empty object, and also if I put it in the view {{rooms}}
it even shows me all the rooms that the user has.
So how here's my question, How can I query specific user info with my own indexes and pass it to a $firebaseArray in order to sync with my view?
OBS: console.log(rData.val())
prints the right objects that I would like to have in the $scope.room variable.
This is the reference where I found the "query" https://www.firebase.com/blog/2013-04-12-denormalizing-is-normal.html