我試圖模仿類似於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