如何设计CMS的资产表(二对多关系?..) [英] How to design assets table for CMS (two-to-many relationship?..)

查看:179
本文介绍了如何设计CMS的资产表(二对多关系?..)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用一个简单的CMS,如web应用程序的数据库。基本上它由作为内容组的一部分的内容的位组成。喜欢作为页面一部分的文本。为此,我想到一个表和一个文本表与1:n的关系。

I'm working on a database for a simple CMS like web-app. Basically it consists of bits of content that are part of a contentgroup. Like pieces of text that are part of a page. For that I was thinking of a page table and a text table with a 1:n relationship.

我还希望资源链接到 页面或文本。因此,一段文字可以有缩略图链接到它,但一个页面可以有一个缩略图链接到它。不知怎的,我只是不知道如何做得很好。我应该使用 pageId textId 资产 >并确保每行只使用其中一个?

Thing is I also want assets to be linked to either a page or a text. So a piece of text could have a thumbnail linked to it, but also a page could have a thumbnail linked to it. Somehow I just can't figure out how to do that nicely. Should I make an assets table with the collumns pageId and textId and make sure only one of them is used each row? Feels a little weird to me.. Or do I just have to make two different asset tables?

希望你们能帮我解决这个问题。

Hope you guys can help me with this!

推荐答案

通常有两种方法来处理这种情况:

There are generally two ways to handle such situation:



$ b>

$ b

>

...但是,这可能是一个只有两个子表的overkill。 OTOH,随着表的数量在关系的任一侧增长,该方案可以避免关系乘法,例如:

...however, this is probably an overkill with just two child tables. OTOH, as the number of tables grows on either side of the relationship, this scheme can avoid "relationship multiplication", for example:

有关如何在关系数据库中实现继承的一些提示,请查看此帖

For some hints on how to implement inheritance in a relational database, take a look at this post.

这篇关于如何设计CMS的资产表(二对多关系?..)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆