Wednesday, March 15, 2017

Should both tables have user_id, even though one-to-one relationship?

I have got two tables subscriptions and payments. These two are related with a one-to-one relation. Basically every subscription belongs to a user (via user_id) and every payment belongs to a user as well. (yes I know) Because they are bond with a one-to-one relation, there is logically no need that both carry the user_id row. But it's vital for both that they show the user they belong to and I am not sure. Should I rely on that bond or would it be okay that both keep their user_id (even they will be same) ? This is more of a theoretical question but a little example of the tables are below.

payments
id   user_id   paymentstuff  ...
1    42         ...
2    16         ...

subscriptions 
id   payment_id   user_id   subscriptionstuff  ...
1    1            42        ...
2    2            16        ...

users
id   name   lname userstuff  ...
16   john   doe   ...
42   jane   foe   ...



via Skeletor

Advertisement