Database Modeling: Facebook like messages

后端 未结 2 450
臣服心动
臣服心动 2021-02-06 09:07

I\'m trying to mimic something similar to FB. Basically, users can post comments in various parts of a user\'s profile (e.g. \"wall\", a \"photo\", etc.). I think the following

2条回答
  •  礼貌的吻别
    2021-02-06 09:48

    You could have your table message, and then n:m relationship tables, i.e.

    message_to_wall:
    - messageID
    - wallID
    
    message_to_media:
    - messageID
    - mediaID
    

    This way you keep the referential integrity and only have one message table.

    This of course would technically allow it to have a message posted to a wall AND to a media item (photo, etc.). So you can't easily restrict this.

    Otherwise - if you do not really require a relational database, you could think about using a NoSQL database like CouchDB or MongoDB. You can store all those comments right on the wall or media document. That way you don't have all those required JOIN queries and the comments are all linked to the media or wall.

提交回复
热议问题