Reputation: 703
I have table like below.
I want to store user roles like admin,reader,writer
How can I store the values in my table.
I searched in google and many results such as 2 types.
Which of the above two method is better for development ?
Tell me the advantage and dis-advantage of both please...
Thanks & Regards
Upvotes: 0
Views: 1439
Reputation: 38672
If you user is having more than one user roles, so definitely it will define as one to many relationship.
So adding table with permutations alone with user Id is best option. Cz one user can have many user roles.
this kind of combination never happens (one-to-one)
user A - admin
User B - writer
User C - reader
Possible is (one-to-many) or (many-to-one)
User A- Admin + reader
User B - reader + writer
user C - Admin + reader + writer
user D - Admin + writer
.....
as well as read these too
Upvotes: 0
Reputation: 24960
The reasons you want the second choice include, mainly
find_in_set()
See Junction Tables or associations tables (more simplified)
See Nightmare Coding without it (and slow performance as all get up).
Upvotes: 1