Domanda

I have created a database design

enter image description here

Description

A user can send a friend request to another user, so here : we have a table FRIENDSHIP containing the id of the sender and recipient.

Every friendship, can be part of one or more FRIENDLISTS (Just like Google+ does) ...A user can add another user to 1 or more lists (Many to many relation), and that's why I added the table FRIENDSHIP_FRIENDLIST.

But, on the other hand, If the sender added the recipient in a "FRIENDLIST" labeled "Family", it doesn't mean that the "sender" will be added in a "FRIENDLIST" of the recipient labeled "Family" too.

This is because every user has his own and separated Friendlists, so to know the friendlist, we must know the user first.

But this design leads to a closed and inconvenient relation as you can see, and I think I have some design problems here.

what do you think is wrong here?

È stato utile?

Soluzione

Correct!

  • You do not need to qualify/identify the ownership or direct participation for any group ( friendlist) as there are exactly the same lists ( or groups) avaiable for every ( and each) user and he/she only participates ( are related) to one ore more groups ( lists) of friendship (the lower associative entity) by a relation of FRIENDSHIP (the entity that implements a self-relationship) So, as you correctly rethought there is no need for the relationship between USER and the FRIENDSHIP_LIST! It would be redundant and even bring problems such this kind of "over-relationship" modeling, because the matter of knowing on which groups are a certain USER is more a matter of processing data ( querying). PS. My only modeling remark point is that the simple 0..N relationship between USER and FRIENDSHIP could be better represented ( as an alternative modeling) by a two simple relationships of USER to show that either the user as the other-user comes from the same entity ( table).

Altri suggerimenti

Okey, I found a solution...there's no problem anymore.

Since the table Friendship will hold two records for every friendship relations, (two raws).

Exemple:

TABLE FRIENDSHIP

friendship_id  |   user_id    |   other_user

1                     1              2
2                     2              1

TABLE FRIENDLIST

friendlist_id         |     label
1                            friends
2                            family
3                            work

TABLE FRIENDSHIP_FRIENDLIST

friendship_id   |   friendlist_id
1                   2
1                   3
2                   1

This way, I don't need a relation between table user and table friendlist, since I will use user_id in the table FRIENDSHIP to know the USER to whom the current friendlist belongs to.

The new design will be :

enter image description here

thank you

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