Crazylife's avatar

Table relationships

I have my database design structure with users, user_profiles, complaints, complaint_user_profile. If i want to store log or documents submitted from the user, can i link to complaint_user? For example, i have another table called complaint_user_profile_documents or complaint_user_profile_logs.

Can i do so?

0 likes
3 replies
Tray2's avatar

Sure you can but try to keep the data model as simple as possible. Also remember to try to follow Laravel's naming convention.

Crazylife's avatar

@Tray2 Let's say if i have complaint_user_profile as my pivot table. If I want to have another table to link with it, I just name it as complaint_user_profile_logs ? Or you have other way to make it looks simple? But i guess this is the only way right if i need to actually link it from complaint_user_profile by adding a id to pivot table.

Tray2's avatar

@Crazylife Not necessarily.

I'm thinking that a user can have only one profile so here will be a one to one relation between user and profile. Complaints sounds like a user can have multiple complaints so a one to many relation between users and complaints. Any documents that are uploaded with the complaint could be a one to many relation as well and warrant it's own table just for the complaint id and the file path. When it comes to logging I would just keep the complaint in the complaints table and use some kind of status to filter them out from the ongoing complaints. If we are talking millions of complaints then there are options to move them to a log table of some kind or you can also use partitions to seperate them.

That being said I would probably do something like this

I would name my tables a little differently and as described above I would only use four tables.

  • users
  • profiles (no need to prefix with users unless you have more than one kind of profile)
  • complaints
  • complaint_documents

Please or to participate in this conversation.