0

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?

Community
  • 1
  • 1
kwngo
  • 9
  • 1
  • 3
  • One way would be to include the user's name in the Message, in addition to their uid. This will allow you to render the list of messages, without having to "join in" the user. Have a look here: http://stackoverflow.com/questions/30693785/how-to-write-denormalized-data-in-firebase/30699277#30699277 – Frank van Puffelen Jun 16 '15 at 18:31
  • Thanks Frank, guess denormalization is the way to go! – kwngo Jun 17 '15 at 00:06

0 Answers0