0

I am trying to model a database for my current project and I came across a new problem. I have a Project which is supervised by Supervisor, Coordinator and Company. So Project table has Supervisor.id as foreign key and so on. There is also Student table which contains Project.is as a foreign key (because many users can do a project). This is how it is right now. What I would like to do is to have a User table containing a column named type which allows me to see what the role of that particular user is (also student). Even though the table will contain many NULL entries, I will have far less redundant code.

However, the main reason I want to have one User table is that I am using CakePHP and it is not easy to have different models log in. Is this possible in a nice way?

Thanks

EDIT: Maybe I should say that every one of these roles will have different permissions.

4

2 回答 2

1

我看到三个表:USERGROUPROLE

用户将被分配到组,组被赋予角色。我认为你需要三个,而不是一个。

基数很重要:我可以看到 aUSER可以分配给许多GROUPS; aGROUP可以有很多USERS;aROLE可以分配给几个GROUPS;一个GROUP可以有很多ROLES。还有很多对很多的 JOIN 表:

USER <-> USER_GROUP <-> GROUP <-> GROUP_ROLE <-> ROLE

这是标准化的 - 没有任何东西以这种方式重复。USER、GROUP 和 ROLE 具有主键。JOIN 表主键是每行中两个 ID 的组合。

于 2013-07-24T15:31:26.423 回答
0

这取决于您将如何使用您的关联。

为什么不

例如:如果您稍后使用关系到输出数据并且您确定您的数据库方案不会改变,那么......为什么不呢?您的主要目标:代码质量和开发速度,因此,无论您将拥有多少带有 null 的列。

如果您不确定您的要求或计划扩展数据库方案,您可以使用两列

  • 主管模型
  • supervisor_id

它将存储适当的值:Company77 (我的意思是 77 它是 come Company 的 id)

另一种方法

您可以为您的 supervisor_id 使用UUID,这样,它将在多个表中是唯一的,并且您没有太多NULL额外的列。

于 2013-07-24T15:48:38.003 回答