如果我有兩個表:A(id,...其他一些列)和B(id,...其他一些列)。我需要將評論(另一個表:id,文本,作者)與A和B對象關聯起來。如何構建不同類型的一對多關係?
我可以爲此創建第四張表:comment_id,table_id(A或B或其他人),item_id?我的意思是一些sqlalchemy方式?
現在我只知道這兩個解決方案: http://bpaste.net/show/27149/ - 對於每個A和B,將有單獨的表格與評論。我認爲這不是一個好主意,因爲這些表格(應該)是相同的,如果我想看到某個作者的所有評論 - 這將比其他方式更困難,如果有一天會有C表格 - 我將需要創建一個表的評論...
另一種解決方案 - http://bpaste.net/show/27148/。我認爲更好,但我仍然需要爲每個需要評論項目的表創建關聯表。
任何想法?提前致謝。
謝謝你的努力!我覺得第一種方式可以工作,但這並不好,imho:每個評論都會有太多未使用的列(不僅有A和B,還有更多)。第二個是好的,但我覺得沒有用我不確定它是在sqlalchemy中實現的。 – kishkin 2012-04-16 15:16:22
@kishkin我在SQLalchemy的創建者 – mensi 2012-04-16 15:17:23
中加入了一個關於該主題的深入討論的鏈接。感謝,現在會閱讀。 – kishkin 2012-04-16 15:18:38