我试图模仿类似于FB的东西。基本上,用户可以在用户简档的各个部分(例如“墙”,“照片”等)发布评论。我想下面的模型将工作:数据库建模:Facebook的消息
===========================
wall_message
===========================
- id (PK)
- parent_id (FK)
- wall_owner_profile_id (FK, identify whose wall the message is for)
- poster_profile_id (FK)
- message
- timestamp
===========================
media_message
===========================
- id (PK)
- parent_id (FK)
- media_id (FK, identify which photo, video, etc.)
- poster_profile_id (FK)
- message
- timestamp
parent_id
允许将消息“组合”成一个相关的讨论。第一条消息的parent_id
将为0,随后的消息将具有PK作为parent_id
值(创建父 - 子关系)。
poster_profile_id
标识谁发布了该消息。
以上两张表格非常相似。难道是一个好主意,把它们结合在一起,如:
===========================
message
===========================
- id (PK)
- parent_id (FK)
- type (ENUM: "wall", "media", etc.)
- types_id (FK, see explanation below)
- poster_profile_id (FK)
- message
- timestamp
在这种情况下,如果说,type
是“墙”,然后types_id
等于第一个表中的“wall_owner_profile_id”。例如,如果type
是“媒体”,则types_id
等于第二个表的media_id
。
我有点担心,第二种方法需要一列来解释另一列的含义。我认为这个缺点是types_id不会有参照完整性(与“wall_owner_profile_id”和“media_id”不同)。
解决此问题的最佳方法是什么?
编辑1:
看起来这是解决方案迄今:
===========================
message
===========================
- message_id (PK)
- parent_message_id (FK)
- profile_id (FK, referring to who posted the message)
- message
- subject (applicable only for emails)
- timestamp
===========================
wall_message
===========================
- message_id (FK)
- profile_id (FK, referring to who received the message/owner of wall)
===========================
media_message
===========================
- message_id (FK)
- media_id (FK)
===========================
email_message
===========================
- message_id (FK)
- profile_id (FK, referring to who received the message)
你检查新的数据模型? – PerformanceDBA 2010-11-29 13:43:20