开发者

Multiple owners for photo albums - schema question

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 ot开发者_开发百科her 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.


Think of your problem in a Conceptual Data Model instead of purely physical. If you do OO work, that's fine too.

Multiple owners for photo albums - schema question

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.

Multiple owners for photo albums - schema question

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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜