[英]mySQL table design for facebook style posts that suits one-to-many or many-to-many
I am trying to build / design a table that will serve purpose to a post/comment system similar to google+ that can support bidirectional one-to-many/many-to-many relations. 我正在尝试构建/设计一个表格,该表格将用于类似于谷歌+的帖子/评论系统,可以支持双向一对多/多对多关系。 What I have currently is
我现在拥有的是什么
member_id,
post_id,
post_body,
post_date,
post_flagged,
post_shared,
post_likes
I have a comment table thats pretty much the same as the above except it has a comment_id on top of the ones above listed to server as its auto incriminate column. 我有一个与上面几乎相同的注释表,除了它在上面列出的服务器之上有一个comment_id作为其自动判罪列。
What I am ultimately seeking here currently is I guess a sanity check. 我目前最终在这里寻求的是我想进行一次健全检查。 Does the above construct/schema look like it might work?
上面的构造/模式看起来是否可行? would you add/remove/alter it in any way?
你会以任何方式添加/删除/更改它吗? If not/or if so.
如果不是/或如果是。 Can anyone also suggest what might be a good way to do the post_shared column?
任何人都可以建议做post_shared列的好方法吗? Is there some type of object or means of storing data in that column that would serve purpose to the logic of Google+ Circles?
是否存在某种类型的对象或在该列中存储数据的方式,这些对象或方式可用于Google+圈子的逻辑?
post_shared should not be in the main post table. post_shared不应该在主帖子表中。
for a normalized solution, you would want a circles
table, a users
table, a posts
table and some associative tables to tell which ones are related - something like 对于规范化的解决方案,您可能需要一个
circles
表,一个users
表,一个posts
表和一些关联表来说明哪些是相关的 - 类似于
user_circles
post_circles
From what I understand, your post_shared
column is what is really in question here. 根据我的理解,你的
post_shared
专栏是这里真正有用的。 Let's say you have a post that is directed at 5 "circles" (we will steal this term from Google). 假设您有一个针对5个“圈子”的帖子(我们将从谷歌窃取这个词)。 How would you indicate that in your current setup?
您如何在当前设置中指出?
The only way to do this in one field is something like {1, 2, 3, 4, 5}
where those numbers are the circle id's. 在一个字段中执行此操作的唯一方法是
{1, 2, 3, 4, 5}
,其中这些数字是圆圈ID。 This isn't a very good practice. 这不是一个很好的做法。
The best way I can see to accomplish this would be to have this schema: 我能看到完成此任务的最佳方法是使用此架构:
post_id, post_body, post_flagged, post_likes
post_id, post_body, post_flagged, post_likes
circle_id, ...
circle_id, ...
post_id, circle_id
post_id, circle_id
The PostCircles table will show which posts are visible to which circles. PostCircles表格将显示哪些帖子对哪些圈子可见。 In the example above, you have 5 rows in the PostCircles table.
在上面的示例中,PostCircles表中有5行。 Let's say the post id is 1:
假设帖子ID是1:
post_id | circle_id
1 1
1 2
1 3
1 4
1 5
Then you can use your query language to show display the appropriate posts, depending on which circles the viewer is in (note the user schema is not shown in this answer). 然后,您可以使用查询语言显示相应的帖子,具体取决于查看者所在的圈子(请注意,此答案中未显示用户架构)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.