Reputation: 1630
I am working on a social platform like web site. I'm not sure what should be the table structure of this situation;
I will have trips that users will create. And users can add users to the trips that they traveled with.
So;
>One Trip >Many users
Should I create the with just two columns;
>tripID >userID
and adding new row for every new user for the same trip ?
Or do you have any other opinion ?
Thanks for any advice.
Upvotes: 0
Views: 48
Reputation: 10701
You have several different relationships here:
This means a one-to-many for trips to user for creating trips (a user can create many trips, a trip has one creator).
You also have a many-to-many, as a user can go on many trips, and trips can have many users, so you need a join table for that.
I would name the join table trip_users, as that is the two joined entities in alphabetical order, which is a standard in some places:
Upvotes: 2
Reputation: 35323
You have three distinct objects here. A user can be on many trips A trip can have many users. By definition this is a many-to-many relationship. For most RDBMS it needs to be resolved though an associative table. (which is the 3rd object)
Upvotes: 1