【发布时间】:2019-06-18 07:36:18
【问题描述】:
我有实体User 和Location - 类似于商店,我需要添加它们之间的关系,但我不知道这有什么好的做法,因为:
用户可以有 3 种类型:经理、主管或员工,并且:
每个位置都有一个用户作为经理,一个经理有一个位置;
每个位置都有一个用户作为主管,一个主管有多个位置;
每个位置都有很多用户作为员工,一个员工有一个位置;
首先想到的是给用户添加关系:
/**
* @ORM\OneToMany(targetEntity="App\Entity\Location", mappedBy="supervisor")
*/
private $locations;
/**
* @ORM\OneToOne(targetEntity="App\Entity\Location", mappedBy="manager")
*/
private $location;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\Location", inversedBy="employees")
*/
private $wrokLocation;
地点:
/**
* @ORM\ManyToOne(targetEntity="App\Entity\User", inversedBy="locations")
*/
private $supervisor;
/**
* @ORM\OneToOne(targetEntity="App\Entity\User", inversedBy="location")
*/
private $manager;
/**
* @ORM\OneToMany(targetEntity="App\Entity\User", mappedBy="wrokLocation")
*/
private $employees;
但我不知道这是不是最好的方法。
【问题讨论】: