I am developing an application where users post products inside categories. I am using firebase and I am trying to flatten the data on the database but I am not sure about the connections of the posts with the categories.
Here is the database design:
"categories": {
"category1": {
"id": "1",
"name": "computers"
},
"category2": {
"id": "2",
"name": "Furniture"
},
"category3: {
"id": "3",
"names": "Books"
},
}
"users":{
"email": "test@gmail.com"
"posts": {
"post1": {
"id": "1"
"title": "Selling my guitar”,
"categories": {
"category1": "true"
}
}
}
Edit: Maybe smth like this
"categories": {
"category1": {
"id": "1",
"name": "computers",
"posts": {
"post1": true
}
},
"category2": {
"id": "2",
"name": "Furniture"
},
"category3": {
"id": "3",
"names": "Books"
},
}
"users": {
"userid1": {
"email": "test@gmail.com" ,
"posts": {
"post1": "true"
}
}
},
"posts": {
"post1": {
"id": "1",
"title": "Selling my guitar",
"users": {
"user1" : "true"
},
"categories": {
"category1": "true"
}
}
}
So from what I learnt I know posts should be a separate entity but then I am not sure how to connect them.
Let me know how can I improve this database.