-2

Well we have a problem. We are quiet new with firebase and are having some problems with trying to get some FK( or refferences of othre databases) in a new database.

firebase

in the field user i want to get a refference to the table users. So when i try to get data from the table Accounts & check on a userID i should be able to get the user_tracklist instead of making 2 query's

Dylan Gomes
  • 93
  • 11

2 Answers2

2

You can save tracklist node inside accounts/{accountId}/user, so you gonna have two copies of tracklist, one inside the user and another one inside account endpoint.

Save also accountId inside endpoint users in order to be capable of updating duplicates of trackinglist on endpoint accounts/{accountId}/user/trackinglist, when some changes happen with trackinglist entity.

Vladimir Gabrielyan
  • 801
  • 1
  • 11
  • 23
  • Well thats the issue i dont want to store the data twice. I just want a refference Key at my table accounts wich refferences to my table users. Storing data twice will result is to much data when it is getting bigger. I am just wondering if i can get a refference in that field – Dylan Gomes Oct 27 '16 at 14:03
  • 1
    in that case you have to do second request to `users`, there is no way to store some reference which would get you `tracklists`, the only options are duplicate vs 'do two requests'. I would personally prefer duplicate, because if you would have a lot of data it could lead performance issues, you have to get used duplicates, nosql databases are for that purpose, here we do not have joins, foreign keys as we had in sql databases. – Vladimir Gabrielyan Oct 27 '16 at 14:17
0

Please come out of relational DB world. firebase-database have no concepts of JOIN,WHERE clauses. It works on concept of JSON Objects .

Keep in mind:

  1. Firebase suggests to denormalize your data as possible as you can do. She loves duplication of data

    Reference: Denormalizing Your Data is Normal

  2. Firebase uses Sockets, you established connection once and then pipeline your queries (bring me a account(s), now bring me user of that account, and blah blah blah). So don't worry about making multiple queries if you need.

Refer to this SO Question

In your data structure,you tried to flatten/denormalize your data but

Change this:

user:"{deftones:true}"

To:

-user
   -deftones:true

and to understand how you can retrieve referential data you must have look on article which I mentioned above

Community
  • 1
  • 1
Zaid Mirza
  • 3,540
  • 2
  • 24
  • 40