【发布时间】:2020-04-26 13:51:06
【问题描述】:
我需要一些帮助来了解三向映射。
我有一个实体 Student 和一个实体 Parent,显然一个家长可以有很多学生,反之亦然,但我需要每个家长和学生之间的额外信息,每个家长和学生都不同。
也许我们有以下数据:
学生 A - 家长 A(无责任),家长 B(有责任) - 即使一位家长承担法律责任而另一方不承担法律责任,但他们仍然是同一个学生的父母。
学生 B - 家长 A(有责任),家长 B(有责任) - 在这种情况下,另一个学生有相同的父母,但这次他们都有法律责任。
要开始我将拥有的基本实体:
class Student
{
// normally would have a ManyToMany here to link parents, but i need the 3rd entity
// to hold whether this student's parent has legal responsibility or not
}
class Parent
{
// normally again would have ManyToMany here to link students to the parent
}
class ParentStudent
{
/**
* @var boolean
* @ORM\Column(type="boolean", options={"default":true})
*/
private $responsibility = true;
// it's this part where i link student to parent and vice versa that's becoming confusing
}
【问题讨论】:
-
删除父母和学生之间的多对多关系,并将其替换为与 ParentStudent 实体的一对多关系。当您的多对多关系需要附加属性时,这是最直接的方法。
-
@Cerad 你能举个例子吗?很难想象它
标签: doctrine-orm symfony4