i am trying to figure out how to store a friend relation beetween my users.
1.
I thought about using arrays, store for each user an array containing all its friends. But i don't know if arrays are suported in MySQL:
-> if they weren't i could also do a string which is the result of friends concatenation. But maybe it would be to much work to explode and implode the content at each time a user wants to get a list of its friends.
2.
then i thought about using a simple paired relation:
user1 is friend with user2 and the relation status: -1 for friends, -0 for friendship requested
so table would be:
Expand|Select|Wrap|Line Numbers
- user1 | user2 | status
- paul | john | 0
- paul | ron | 1
- jimi | paul | 1
Example:
paul asked john to be his friend. -> 0 ->friendship not confirmed yet
paul asked ron to be his friend-> 1 ->friendship confirmed, updated 0->1
This would work fine if:
before i insert a friendship request into the table, i look into "user1" coulumn.
Expand|Select|Wrap|Line Numbers
- if(there is a record of the requesting user into user1){
- insert into coulumn user1
- }
- else{
- insert into column 2
- }
-> john is either on user1 and user2 columns.
THE Question is :
isn't that to much work to perform for a simple friend request insertion?
3.
the other possibility which extends this last one, is not to perform the check at insertion, but then check on select into the two columns:
Example, john wants to see his friends:
Expand|Select|Wrap|Line Numbers
- SELECT user1 and user2
- FROM friends
- WHERE user1 = john OR user2 = john
Experts, what do you think i should do?
Thankyou very much
bilibytes