【发布时间】:2020-01-02 07:05:29
【问题描述】:
首先,我创建了业务规则:
用户可以在城市发表评论,用户cmet可以被其他用户回答。
cmets 层次结构是:根 cmets、对根 cmets 的回答、对回答根 cmets 的回答。所以, 层次结构只有一层。
关于我的想法的示例:
Ana123: I was in Seville and I love it. (Root comment)
Juan321: Ohh, yesss it's beautiful. (answer to root comments)
Manuel99: "Juan321" Yessss :D (answer to answer root comments)
然后:
- 一个用户在零个或多个城市中聚集。
- 一个城市被零个或多个用户评论。
- 一个用户回答零个或多个用户。
- 一个用户被零个或多个用户回答。
- 用户拥有:ID、姓名、电子邮件、密码。
- 城市有:ID、名称、描述。
注意:我删除了红色关系,因为它与 CITY 隔离,对我来说没有多大意义。
所以从 USER - CITY 关系我得到了下一张表:
TABLE: user_comments_city
id_comment(PK) | id_user | id_city | text | date
但正如我所说,我只将两个关系组合在一个中,我添加了“answer_comment”字段(使用这个 我认为我实现了这一点)。我将使用上面的示例:
TABLE: user_comments_city
id_comment(PK) | id_user | id_city | text | date | answer_comment
... ... ... ... ... ... (NOTE: "..." represents other comments)
15 2 4 I was in Seville and I love it. 20/08/2019 20:20
16 13 4 Ohh, yesss it's beautiful. 20/08/2019 21:31 15
... ... ... ... ...
21 9 4 Yessss :D 21/08/2019 11:20 16
22 17 4 I love it too :) 21/08/2019 14:00 15
所以,我问:我可以这样做吗?有没有一种有效的方法来实现这一目标?
【问题讨论】:
-
你的意思是“有没有一种有效的方法来实现这一目标?”看起来你已经实现了你想要的?
标签: database-design relationship entity-relationship business-rules