Domanda

I have a table where I'm storing "Friend" associations. So column 1 is userID and column2 is friendID (where friendID is just another userID from the users table.

I've been planning to have two entries per relationship. To explain, let's say user 100 wants to be friends with 200. My table would look like this:

USERID = 100
FRIENDID = 200
STATUS = 'friend'

But then also

USERID = 200
FRIENDID = 100
STATUS = 'friend'

After they accept the friend request. The idea is that the relationship is defined in both directions so I can set different status depending on whether they're "requesting friendship" or if the users want to categorize or put custom notes on the friends.

I wanted to use the userID and FriendID columns as a composite key, but will MYSQL die in a fire if I have the same combination of userID and FriendID in two places (even though they're reversed)?

È stato utile?

Soluzione

You should have FriendID and UserID as a composite key. This will mean that you can't have 2 different statuses for the same friendship. Why would MySQL crash?

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top