Vimo's avatar
Level 4

Tips for database design

How would you design your database if a user can have multiple types of invites? Invites belonging to admins, system, companies. I have a page showing all invites, which hasn't been problematic. Just wondering how I effectively can accept these invites using API calls?

I want to do something like this: /invite/123/, but since the IDs are different, I am not sure how to tackle this. Should my front-end know what kind of model and use conditions to make it call a specific API route?

Thanks!

0 likes
2 replies
Tray2's avatar
Tray2
Best Answer
Level 74

I would have one invites table and then have a type field that tells what kind of invite it is. If I then need to connect some foreign key I just add that so the table could look something like

  • id
  • invitation
  • type
  • type id

That way it doesn't matter what model has created the invite when you do a serach like /invite/123.

Vimo's avatar
Level 4

Sounds like a great approach. Just what I needed! Thanks!

Please or to participate in this conversation.