This might be too broad a question but I'm building a blog app (Express/React/Postgres) and I'm new to the backend world.
I have tables for users and posts and if I want to track user reactions (thumbsup, smile, laugh, etc.) would you do that in the posts table or create a new reactions table with fkey references to users.id and posts.id?
I ask because I did the latter, then realized that posts can have multiple users and reactions, so I'm not sure the right / best way to do that, even with JOIN.
If it were JSON, this is how I see it in my mind, but I don't know how to translate this to SQL tables and knex queries.
[
{
"posts": [
{
"post_id": "1234567890ABCDEF",
"content": "foo bar",
"created_at": "01/18/2020",
"reactions": {
"users": [
{
"user_id": "D237NH23DGU6",
"reaction": "thumbsup"
},
{
"user_id": "DVSY8N8VSDYN6",
"reaction": "angry"
},
{
"user_id": "3D2J892D3J8933",
"reaction": "laughing"
},
{
"user_id": "23987DNHIUO8DD",
"reaction": "thumbsup"
}
]
}
},
{
"post_id": "99FJ48FJ4F8JHSH",
"content": "bar foo",
"created_at": "01/18/2020",
"reactions": {
"users": [
{
"user_id": "DSDF879344FH97",
"reaction": "sad"
},
{
"user_id": "8S7DF62HF87H34F",
"reaction": "peace"
},
{
"user_id": "37HHF783H4K47834",
"reaction": "laughing"
}
]
}
},
{
"post_id": "1234567890ABCDEF",
"content": "foo foo bar bar",
"created_at": "01/18/2020",
"reactions": {
"users": [
{
"user_id": "SDFWEF934949J4",
"reaction": "thumbsup"
},
{
"user_id": "R9TVU8TRVU89",
"reaction": "angry"
},
{
"user_id": "IJFG0F8GJ9",
"reaction": "laughing"
},
{
"user_id": "3F4V3NHVF43N8",
"reaction": "thumbsup"
},
{
"user_id": "VXDRTHVHM6D7",
"reaction": "angry"
},
{
"user_id": "A9SFDHSFDH78",
"reaction": "laughing"
},
{
"user_id": "DFSM8H87M9N",
"reaction": "thumbsup"
}
]
}
}
]
}
]