0

Im new to Firebase, I have Structure my Data on firebase using Indices for maintaining relationshi as described in below articles

https://www.firebase.com/docs/web/guide/structuring-data.html https://www.firebase.com/blog/2013-04-12-denormalizing-is-normal.html

I just want to clear my retrieval concept on firebase.

as mention in above links

{  
  links:{  
    link1:{  
      title:"Example",
      href:"http://example.org",
      submitted:"user1",
      comments:{  
        comment1:true
      }
    }
  }
}

when I access link1, response contains link1 data as well as comments: {comment1:true}. Instead of comment1 actual text, accessing link1 gives comment's ID i.e, comment1. its mean when I access link1, it gives me the Ids of comments belongs to that link. so I have to retrieve comments mannually requesting firebase again based on comments ids received in link1 response? Please clear my concept : )

Grant
  • 446
  • 6
  • 24
Zaid Mirza
  • 3,540
  • 2
  • 24
  • 40
  • @Grant , Firebase preffered flatten data. You can see here .https://www.firebase.com/blog/2013-04-12-denormalizing-is-normal.html – Zaid Mirza May 12 '16 at 12:15
  • @Grant . Code is just a sample. my actual work is not on links and comments but something likes it. one to many relation – Zaid Mirza May 12 '16 at 12:22
  • @Grant. I have took this piece of code from article which I mention above in comments – Zaid Mirza May 12 '16 at 12:24
  • Yes, you will indeed have to load each items. Essentially you're doing a client-side join operation. Contrary to what many developers expect, this is a quite fast operation in Firebase for reasonable sizes lists. See my answer here for why that is: http://stackoverflow.com/questions/35931526/speed-up-fetching-posts-for-my-social-network-app-by-using-query-instead-of-obse/35932786#35932786 – Frank van Puffelen May 12 '16 at 14:40
  • Is the goal to get all the comments for link1? – Jay May 12 '16 at 17:16
  • @FrankvanPuffelen Thanks Sir. For explaining moree.. – Zaid Mirza May 16 '16 at 08:20

1 Answers1

1

Yes, your concept is correct, you will flatten out the data in firebase and then retrieve comments by using the id from the previous read

Grant
  • 446
  • 6
  • 24
  • means? I have to make two requests to firebase? one for links data and then comment? if one link have hundred comments then will have to make 100 requests to get comment text? – Zaid Mirza May 12 '16 at 12:28
  • you may need to make 100 queries but that won't translate to 100 HTTP requests due to the fact firebase uses sockets – Grant May 12 '16 at 12:34
  • 1
    Thanxxx Buddy, You help me in to improve my concept – Zaid Mirza May 16 '16 at 08:22