database-designsocial-networking

How to model database tables for implementing Friend relationship?


I'm trying to design a data model that denotes one user being the friend of another user. This is what i've come up with so far, but it seems clunky, is there a better solution?

User
=====
Id
Name
etc...

UserFriend
===========
UserId
FriendId
IsMutual
IsBlocked

Solution

  • UserRelationship
    ====
    RelatingUserID
    RelatedUserID
    Type[friend, block, etc]
    

    Agree that mutuality doesn't belong as a column; breaks normalization.