与mysql中的递归一对多关系需要至少4个表? [英] Does a many-to-many relationship with a recursive one-to-many in mysql require at least 4 tables?

查看:446
本文介绍了与mysql中的递归一对多关系需要至少4个表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下关系(业务规则):

I have the following relationships (Business rules):


  • User_Company :多对多每个用户有多个公司,每个公司有多个用户)

  • 所有权:一对一(对于关系表中的每个条目,它指定用户是否为所有者或雇员,如果所有者的百分比必须在那里)

  • Company_ownership :一对一的公司(递归关系),因为另一家公司也可以一个公司的所有者,必须给出百分比。

  • User_Company : Many-to-many (multiple companies per user, multiple users per company)
  • Ownership : One-to-One (For each entry in relationship table, it specifies whether user is an owner or employee. If owner then a percentage must be there)
  • Company_ownership : One-to-many for company (Recursive relationship), as another company can also be an owner in a company, percentage must be given.

所以所有权或公司可以由多个公司和用户。

所以我开发了以下内容:

So I have developed the following:

那么还有必须至少4个表可以用于这种关系,也可以简化。
我觉得这是相当复杂的,对于另一个开发人员来说不是直观的?如何优化和优雅地排列?

So does there have to be at least 4 tables for this sort of relationship or can it be simplified. I feel it is quite complicated and would not be intuitive for another developer? How could it be optimized and elegantly arranged?

推荐答案

我认为所有权和就业是不同的概念,更建议有他们分开。

想想约翰谁是 A 公司的所有者之一,同时他也是 A 。


公司和人员可以有一个基础来减少实体的冗余。


I think ownership and employment are different concepts, that would be more advised to have them separated.
Think about John who is one of the owners of A company and in the mean time he is the CTO of A.

Company and People can have a base to reduce redundancy of entities.

这篇关于与mysql中的递归一对多关系需要至少4个表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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