0

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.

Sina
  • 1,092
  • 1
  • 9
  • 19

1 Answers1

0

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.

Menachem Bazian
  • 397
  • 2
  • 5
  • 18
  • thanks for answering. the user who is invited is not available yet! the invitation is to invite him to join the app. – Sina May 17 '17 at 18:19
  • OK. So let's define the workflow. I invite you. You get an email with a link that points to the invitation. At that point, three fields are populated: The primary key, my user ID and the APP id. When you signup with the invitation, you will get a user iD and you can put that into the invitation row at that point. – Menachem Bazian May 17 '17 at 18:26
  • i don't need to put the new user id into invitation row. i will expire the invitation token and add the new user id to the app which invitation points to in another table like groups. – Sina May 17 '17 at 18:38
  • OK. Then you can remove that field from the invitations table. The rest of the solution is valid based on our discussion, though. – Menachem Bazian May 17 '17 at 18:50
  • Does not seem to normalized! I need a better design. – Sina May 18 '17 at 02:02
  • Sure it is. That is exactly what normalization calls for. It's a standard link table design. – Menachem Bazian May 19 '17 at 14:33