相册的多个所有者 - 架构问题

发布于 2024-10-11 19:05:13 字数 282 浏览 4 评论 0原文

我将如何为属于用户、事件、组、网络、页面的相册创建关系(我想支持 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

り繁华旳梦境 2024-10-18 19:05:13

在概念数据模型而不是纯粹的物理模型中思考您的问题。如果你从事面向对象的工作,那也很好。
CDM

半圆是继承运算符。所以Event、User、Network、Page都继承自Owner。

当您将其生成为物理模型时,您将使用这些设置。

alt text

这样,您就可以得到一个表格,其中包含可以拥有照片和所有常见属性的所有内容。然后,每个子表将从父表继承 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.
CDM

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.

alt text

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.

用心笑 2024-10-18 19:05:13

创建一个包含三列的表,相册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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文