是否应该定义所有关系?在这种情况下,应该"公司广告"关系也被定义?我的意思是优点是你不需要加入很多表。什么是对的?
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;
vs广告:
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;
答案 0 :(得分:0)
由于广告主要与某个人相关联,因此我只关联广告 - >人际关系。不过这是我对一个简单场景的看法,它让事情变得简单。