I'm working on a messaging app. I want to be able to display the senders username. I'm currently modeling messages and users and trying to display username by query the usersRef by the authData.uid.
Messages {
sender: authData.uid,
body: decoded,
created_at: Firebase.ServerValue.TIMESTAMP
}
Users {
email: user.email,
username: user.username,
created_at: Firebase.ServerValue.TIMESTAMP
}
// This returns https://talklah.firebaseio.com/users/simplelogin%3A3/email
$scope.getUsername = function(sender) {
var usersRef = ref.child("users");
return usersRef.child(sender).child('email');
}
// I want to display something like this in my templates
message: Hey, how are you? (sent by [username])
How should I be approaching a problem like this?