NormalizedCollection orderBy
Opened this issue · 1 comments
KyDenZ commented
Hello,
I blocked for some days to retrieve data from Firebase in descending order and in relation to the connected user:
Firebase :
{
"Chats": {
"chats_1000": {
"FriendChat": {
"user_1": true,
"user_2": true
},
"chatDate": 1466755200,
"chatId": "chats_1000"
}
},
"user": {
"user_1": {
"name": "test",
"chats": {
"chats_1000": true
}
}
}
}
Controller
var ref = new Firebase("https://name.firebaseio.com/");
var norm = new Firebase.util.NormalizedCollection(
[ref.child('user/' + userId + '/chats'), 'chat'],
[ref.child('Chats').orderByChild("dateTime"), 'Chats.chatId', 'chat']
);
var ref = norm.select('chat.chatId').ref();
ref.once("value", function (snap) {
console.log('chat'+snap.val());
});
I have no error but no return Firebase .
If I exchange the two links Firebase I 'm conversation sorted in chronological order , but I have every conversation. I would just have the user logged conversations :
Controller
var ref = new Firebase("https://name.firebaseio.com/");
var norm = new Firebase.util.NormalizedCollection(
[ref.child('Chats').orderByChild("dateTime"), 'Chats'],
[ref.child('user/' + userId + '/chats'), 'chat', 'Chats.chatId']
);
var ref = norm.select('Chats.chatId').ref();
ref.once("value", function (snap) {
console.log('chat'+snap.val());
});
I thank you in advance
Deadsoil commented
This is pretty old, so I assume you have fixed this by now.
The error is on the line calling the chat id's from the user.
[ref.child('user/' + userId + '/chats'), 'chat'],
you need to have 'Chats' instead of 'chat' as on the line calling the chats you have put 'Chats.chatId'.
Hope this helps.