1

I would like to understand a basic concept regarding Firebase data structure and the callbacks.

If i have a users object:

users
    userid
       username: "my name"
       userpic: "http://coolpic.jpg"
        ....

and posts object:

posts
   postid
       post message: "hello world"
       userid: "12345"

My goal is to show a listView containing posts where each post shows the username + user pic (who wrote the post) and the post message. From what I've seen so far, if i call for post info, and then for user info (based on the userid within that post) the callback system gets the user info only after the view is populated. So i can't do something like :

  1. get post message + userid from posts object
  2. get user info from users object based on the userid i just got from posts object.

I noticed the "Promises" mechanic but it's only for Java Script, so the only solution i see is to store the user pic, and user name within the post object:

 posts  
     postid
          post message: "hello world"
          userid: "12345"
          username: "my name"
          userpic: "http://coolpic.jpg"

Is there another solution? it seems like a nightmare to deal with, if a user wants to change his userpic or username.

Dawson
  • 4,391
  • 2
  • 24
  • 33
bbenis
  • 485
  • 2
  • 6
  • 10
  • http://stackoverflow.com/questions/1995216/join-operation-with-nosql – Shubhank Jun 01 '16 at 12:26
  • Well I guess you don't have much option but to make to separate callbacks for post info and user info. The Solution that you suggested at the end is not a good practice though, it will cause a bigger nightmare once you go deep in your project. – Parag Kadam Jun 01 '16 at 12:39

0 Answers0