相册的多个所有者 - 架构问题
我将如何为属于用户、事件、组、网络、页面的相册创建关系(我想支持 x 个可能的所有者)?如果可能的话,甚至稍后支持多个所有者。
一种方法是在专辑表中设置这些列,其中之一具有 FK ID,其余为空。但问题是,当我添加更多所有者类型时,我必须不断更改表以添加更多列。
另一种方法是为每种所有者类型创建单独的照片表。
这些方法都不能很好地扩展。还有其他方法可以从一个可扩展的表中为不同所有者类型拥有相册(意味着更少的连接并且易于查询,因为读取性能是我的第一要求?
平台是 MySQL/PHP。
How would i go about creating a relationship for photo albums that belong to either a user, event, group, network, page (I want to support x number of possible owners)? If possible even support multiple owners lateron.
One way is to have columns in the album table for these with one of them have a FK ID and rest be null. But problem is as i add more owner types i have to keep altering the table to add more columns
The other way is to have separate photo tables for each of these owner types.
None of these methods scale well. Any other methods to own photo albums for different owner types from one table that will scale (meaning have less joins and be easy to query as read performance is my #1 requirement?
Platform is MySQL/PHP.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在概念数据模型而不是纯粹的物理模型中思考您的问题。如果你从事面向对象的工作,那也很好。
半圆是继承运算符。所以Event、User、Network、Page都继承自Owner。
当您将其生成为物理模型时,您将使用这些设置。
这样,您就可以得到一个表格,其中包含可以拥有照片和所有常见属性的所有内容。然后,每个子表将从父表继承 PI,并具有特定于它的属性。照片表的FK将进入Owner表。
您未来的照片多所有者目标将从照片表上的所有者 ID 作为 FK 更改为所有者和照片之间的多:对:多映射表。如果您使用这些构造,那真的很容易。
Think of your problem in a Conceptual Data Model instead of purely physical. If you do OO work, that's fine too.
The semicircle is an inheritance operator. So Event, User, Network, Page all inherit from Owner.
When you generate this to a Physical model you'll use these settings.
This way you get one table of everything which can own a photo and all of the common attributes. Then each child table will inherit the PI from the parent, and have attributes specific to it. The FK of the photo table will go to the Owner table.
Your future goal of many owners for a photo changes from a Owner ID as FK on the Photo table to a many:to:many mapping table between owner and photo. Really easy if you use these constructs.
创建一个包含三列的表,相册FK、所有者FK和所有者类型,所有者类型是用户、偶数、组等的可枚举类型。
Create a table with three columns, album FK, owner FK, and owner type with owner type being a enumerable type for user, even, group, etc.