如何将用户绑定到不同的组织、大学、公司,扮演不同的角色? [英] How to bind users to different organizations, universities, companies with different roles?
问题描述
USERS
1. GFER: SUPERADMIN
Foundation(VAG):
2. John: Incharge
3. Jessi: IT Head
University(MIT):
4: Bill: Adminstrator
5: Gates: Prinicipal investigator
6: Donald: Researcher
Organizations(YE):
6. Jason: Head of R&D
7. Johnny: Researcher
没有用户就无法存在大学、组织或公司.总会存在创建它或拥有它的用户.每个用户也会有一个个人资料.
University, organization or company can't exist without a user. There would always exist a user who'll create it or own it. And every user would have a personal profile as well.
架构如下所示:
用户
- email
- name
角色:
- id
- name
大学(简介):
- name
- short history
组织(个人资料):
- name
- logo of the brand
基金会(简介):
- name
- Adminstrative contacts
我如何知道用户绑定到哪个表(基金会、组织或大学)以及它在该组(基金会、组织或大学)中扮演什么角色?我想像这样创建一个桥接表:
How can i know a user is bind to which table(foundation, organization or university) and what role does it have in that group(foundation, organization or university)? I thought to create a bridge table like this:
Group:
- id
- name
- type(University, Foundation, Organization)
Group_members:
- id
- roleId
- groupId
- userId
但问题是我无法创建 groups
表,因为大学、基金会和组织的数据彼此完全不同.所以我必须为每个人创建一个单独的表.我该如何解决这个问题?
But the problem is that i can't create a groups
table as data for university, foundation and organization is totally different for each other. So i'll have to create a separate table for each. How can i solve this problem?
推荐答案
-- User USR exists.
--
user {USR}
PK {USR}
-- Role ROL exists.
--
role_ {ROL}
PK {ROL}
Xorg
是大学、组织或基金会的通用术语.Discriminator TYP
用于区分这三者.
Xorg
is a generic term for a university, an organization, or a foundation.
Discriminator TYP
is used to distinguish between these three.
-- Xorg XOG, of type TYP, named XNM was created
-- (is owned) by user USR.
--
xorg {XOG, TYP, USR, XNM, ...common_cols}
PK {XOG}
SK {XOG, TYP}
CHECK TYP in {'U', 'O', 'F'}
FK {USR} REFERENCES user {USR}
-- University (xorg) XOG, of xorg-type TYP = 'U', exists.
--
university {XOG, TYP, ...university_specific_cols}
PK {XOG}
CHECK TYP = 'U'
FK {XOG, TYP} REFERENCES xorg {XOG, TYP}
-- Organization (xorg) XOG, of xorg-type TYP = 'O', exists.
--
organization {XOG, TYP, ...organization_specific_cols}
PK {XOG}
CHECK TYP = 'O'
FK {XOG, TYP} REFERENCES xorg {XOG, TYP}
-- Foundation (xorg) XOG, of xorg-type TYP = 'F', exists.
--
organization {XOG, TYP, ...foundation_specific_cols}
PK {XOG}
CHECK TYP = 'F'
FK {XOG, TYP} REFERENCES xorg {XOG, TYP}
-- User USR is member of xorg XOG, of xorg-type TYP,
-- in role ROL.
--
user_xorg {USR, XOG, TYP, ROL}
PK {USR, XOG}
FK1 {XOG, TYP} REFERENCES
xorg {XOG, TYP}
FK2 {USR} REFERENCES user {USR}
FK3 {ROL} REFERENCES role_ {ROL}
注意:
All attributes (columns) NOT NULL
PK = Primary Key
AK = Alternate Key (Unique)
SK = Proper Superkey (Unique)
FK = Foreign Key
关于子类型的一句话.为子类型实现约束的正确方法是使用断言 (CREATE ASSERTION
),但它在主要数据库中仍然不可用.我正在使用 FKs
代替,并且与所有其他替代方法一样,它并不完美.人们争论很多,关于 SO 和 SE-DBA,哪个更好.我鼓励您也检查其他方法.
A word about subtypes. The proper way to implement constraints for subtypes would be to use assertions (CREATE ASSERTION
), but it is still not available in major DBs. I am using FKs
instead, and as all other substitute methods it is not perfect. People argue a lot, on SO and SE-DBA, what is better. I encourage you to check other methods too.
这篇关于如何将用户绑定到不同的组织、大学、公司,扮演不同的角色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!