简体   繁体   English

如何将用户绑定到具有不同角色的不同组织、大学、公司?

[英]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.每个用户也会有一个个人资料。

Schema looks like this:架构如下所示:

User用户

- email
- name

Roles:角色:

 - id
 - name

University(Profile):大学(简介):

 - name
 - short history

Organizatons(Profile):组织机构(简介):

  - name
  - logo of the brand

Foundation(Profile):基金会(简介):

  - 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

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.但问题是我无法创建groups表,因为大学、基金会和组织的数据彼此完全不同。 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 is a generic term for a university, an organization, or a foundation. Xorg是大学、组织或基金会的通用术语。 Discriminator TYP is used to distinguish between these three.鉴别器TYP用于区分这三者。

-- 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}

Note:笔记:

All attributes (columns) NOT NULL

PK = Primary Key
AK = Alternate Key   (Unique)
SK = Proper Superkey (Unique)
FK = Foreign Key

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.为子类型实现约束的正确方法是使用断言( CREATE ASSERTION ),但它在主要数据库中仍然不可用。 I am using FKs instead, and as all other substitute methods it is not perfect.我改用FKs ,与所有其他替代方法一样,它并不完美。 People argue a lot, on SO and SE-DBA, what is better.人们争论很多,关于 SO 和 SE-DBA,什么更好。 I encourage you to check other methods too.我鼓励您也检查其他方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM