mySQL 一对多数据存储
我最近才了解一对多的概念,所以如果这本身有点模糊或断章取义,请原谅。
目前,我正在尝试找出以社交方式构建桌子的最佳方法。我最终想要实现的是 Google+ 墙。例如,关注我的人或我选择查看帖子的人可以看到我发布的内容。我知道我需要两到三张桌子来整理这个烂摊子。这只是如何存储它,以便我可以查询它,这就是我在逻辑上遇到困难的地方。
目前,我正在设想一个表,用于存储成员 ID 和帖子(以及任何其他相关数据,如时间戳等)。另一个表中有两个朋友之间的朋友关联,第三个表存储其他内容,以便我可以将其用作某种交叉引用。但我不知道我是否以正确的方式思考这个问题。正如我所说,我对这个想法很陌生;我无法完全想象它。那么有人对如何构建这些表有任何建议吗?目前并不想弄清楚如何查询它们。只是想弄清楚如何正确使用一对多概念,而我在该主题上所做的所有阅读实际上并没有以示例的形式给我带来太多帮助,甚至与我想要的内容相对接近做。
I've only recently learned of the concept of one-to-many so excuse me if this is a bit vague or out of context per se.
Currently I am trying to figure out what is the best way to build up my tables in a social-esque manner. What I am trying to ultimately achieve is the Google+ wall. Where, say, people who are following me, or people I choose to see a post can see what I post. I know I am going to want two or three tables to sort this mess. It's just how to store it so I can then query against it is where I am having trouble wrapping my head around the logic.
Currently I am envisioning one table where I store a member id, and post (with any other associated data like timestamps etc.). Another table where I have the friend associations between two friends, and a third table that stores something else so I can use it as a cross-reference of sorts. But I don't know if I am thinking this through the right way. As I said I'm new to the idea; I can't picture it fully. So does anyone have any suggestions how to build these tables out? Not really looking to figure out how to query them currently. Just trying to figure out how to use the one-to-many concept properly, and all the reading I have done on the subject really hasn't given me much to work with in the form of examples even relatively close to what I want to do.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您将需要一张用于会员的表
会员(memberId、MemberName、DateJoined 等)
一张表用于具有会员外键的帖子 帖子
(PostId、MemberId、PostDate 等)
一张用于其关注者 关注者
(FollowerId、FollowedId),其中两者都是外国的Members 表的键
You will need one table for members
Members (memberId, MemberName, DateJoined etc)
One for posts with a foreign key to members
Post (PostId, MemberId, PostDate, etc)
One for whose following who
Following (FollowerId, FollowedId) where both are foreign keys to the Members table