2

I'm making this android app using Firebase where I have some books and every user user can set them as read or reading.

I don't know how to do it since Firebase is noSQL and there are no Relations between entities.

There are these three activities: in the first one the user can see all the books and eventually set one as read or reading, in the second there are only books marked ad read and in the third the books marked as reading.

They must be separated, every user has its own.

How can I do this using Firebase realtime database and storage?

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
Fio
  • 43
  • 5

1 Answers1

0

I'd likely create two top-level nodes, for the two types that you have:

  1. Users
  2. Books

And then create two additional top-level nodes for the relations between these:

  1. UserBooks - which is where we tie each user to their books, and track their reading status.
  2. BookUsers - which ties each book to the users. You only need this if you want to show the users for a specific book, but I typically recommend adding it right away.

So a simple model like this could look like:

Users: {
  "uidOfFio": { ... },
  "uidOfPuf": { ... }
},
Books: {
  "idOfBook1": { ... },
  "idOfBook2": { ... }
},
UserBooks: {
  "uidOfFio": {
    "idOfBook1": "Read",
    "idOfBook2": "Reading"
  },
  "uidOfPuf": {
    "idOfBook1": "Reading",
  }
},
BookUsers: {
  "idOfBook1": {
    "uidOfFio": "Read",
    "uidOfPuf": "Reading"
  },
  "idOfBook2": {
    "uidOfFio": "Reading"
  },
}

For more on this, I recommend reading:

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807