是否应该定义所有关系?在这种情况下,是否还应该定义“公司广告”关系?我的意思是,优点是您不需要联接许多表。什么是正确的?

company 1 - n person

person 1 - n advertising

(company 1 - n advertising)


公司:

id | name
1  | xcompany
2  | ycompany


人:

id | name     | company_id
1  | xperson  | 1
2  | yperson  | 2


广告:

id | name     | person_id
1  | xad      | 1
2  | yad      | 2

advertising->person()->company();

SELECT
    *
FROM
    advertising
        LEFT JOIN
    person ON advertising.person_id = person.id
        LEFT JOIN
    company ON person.company_id = company.id;


与广告:

id | name     | person_id | company_id
1  | xad      | 1         | 1
2  | yad      | 2         | 2

$advertising->company();

SELECT
    *
FROM
    advertising
        LEFT JOIN
    company ON advertising.company_id = company.id;

最佳答案

由于广告主要与一个人相关联,因此我只将广告->人际关系相关联。但是,这是我对一个简单方案的看法,它使事情变得简单。

关于mysql - 是否应该定义所有关系?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/49588324/

10-10 06:00