2

I want to create database on Firebase with a many-to-many relationship. I am not sure how to implement the JSON file structure.

The database should work like:

  1. One user will belong to many organisations
  2. One organisation will have many users

I did some structuring like this:

App
-Organisation
--Organisation Name
---Members
-----Member1
-----Member2

-Users
--Member


1
--UserEmail
--Organisations
--User questions

Any suggestions?

B.Y
  • 321
  • 1
  • 4
  • 14

1 Answers1

3

You can organize your Firebase database like following :

users:{
  user1:{
    org:{
      org1 : true;
      org2 : true;
    };
    name: ...;
    ....
  }
  user2:{
    org:{
      org2 : true;
      org3 : true;
    };
    name: ...;
    ....
  };
};
organizations:{
    org1:{
      name: ...;
      users:{
        user1: true;
        user3: true;
      };
      .... 
    };
    org2:{
      name: ...;
      users:{
        user1: true;
        user2: true;
      };
      .... 
    };
    ....
};

Each user will have a org field that will have all the organizations associated with him/her. Likewise Organizations will have a user field that will have all users associated with it.

triandicAnt
  • 1,328
  • 2
  • 15
  • 40