How to associate one table with two tables

96 Views Asked by At

I have a users and apps tables in my application. The relationship between them is one-to-many. An app belongs to a user and a user has many apps. I want to add a invites tables too. which a has a token stored in it. When a user creates an invitation token and pass it to another user, by signing up with that token the new user becomes one of the app's users which I'm storing them as a group in another table. Now the problem is in the sign up page, when the token is passed in I want to say:

John Doe (user who created the invitation token) has invited you to join TechLive (the app user is invited to join) Team.

So from the record in invites table. I need to also fetch the user who created the invitation link or token and because a user can have many apps I need to know which app the link points or belongs to in order to add the user specifically to that app?

Can any one help me with the design schema of the invites table? Thanks in advance.

1

There are 1 best solutions below

6
Menachem Bazian On

If I read your question right, you need an invitations table that has four IDs in it. A primary key for the table and then one each for the user that created the invitation, the app the second user is invited to and then the ID for the user who is being invited.

The first field, as mentioned, is your primary key and the others are foreign keys. The interesting part is that you will have two foreign keys that relate to the user table. One holds the ID for the sending user and the other has the ID for the receiving user.