You can save 2 entries in the friend relationship table. After all, it seems unintuitive to save one. You can save 2 entries to query the friend whose user_id is 2. select friend_id from table where user_id = 2 。 存1条的话比较麻烦些,select friend_id from table where user_id = 2 union select user_id from table where friend_id=2 Let's separate the permission tables. The relationship table maintains relationships, and the permission table maintains permissions. Don't do it together, because you may need to add other permissions in the future, and you will definitely run into trouble if you put them in one table. At least it wouldn't be that troublesome if we separated. Modifications will not affect the relationship table
I feel that these two pieces of data are different in terms of the later needs you mentioned. The user with ID 1 must have more than one friend with ID 2 Furthermore, when Li realizes other needs later, you write Not good together
Two items. 1. The other person is your friend, but you may not be the other person’s. 2. The other party’s settings for you may not be the same as your settings for the other party.
If you have these two needs. Two, the opposite is required, one.
My experience is that 2 is better. First: You are my friend, but I may not be your friend. Second: It’s so convenient to check friends this way, but it’s troublesome to check just one link.
In addition, let’s consider expansion. If we change the friends to a blacklist, then using 2 items, it can be easily expanded. After all, if I block you, you may not block me.
You can save 2 entries in the friend relationship table. After all, it seems unintuitive to save one. You can save 2 entries to query the friend whose user_id is 2.
select friend_id from table where user_id = 2
。 存1条的话比较麻烦些,select friend_id from table where user_id = 2 union select user_id from table where friend_id=2
Let's separate the permission tables. The relationship table maintains relationships, and the permission table maintains permissions. Don't do it together, because you may need to add other permissions in the future, and you will definitely run into trouble if you put them in one table. At least it wouldn't be that troublesome if we separated. Modifications will not affect the relationship tableDepending on business needs, I personally think it’s better to be more detailed
I feel that these two pieces of data are different in terms of the later needs you mentioned. The user with ID 1 must have more than one friend with ID 2
Furthermore, when Li realizes other needs later, you write Not good together
In my opinion, it is necessary to separate
Two items.
1. The other person is your friend, but you may not be the other person’s.
2. The other party’s settings for you may not be the same as your settings for the other party.
If you have these two needs. Two, the opposite is required, one.
My experience is that 2 is better. First: You are my friend, but I may not be your friend. Second: It’s so convenient to check friends this way, but it’s troublesome to check just one link.
In addition, let’s consider expansion. If we change the friends to a blacklist, then using 2 items, it can be easily expanded. After all, if I block you, you may not block me.
Two, similar to following. If you follow him, he may not follow you