I have this structure of Entities
class Group
{
/**
* @var int
* @ORM\Id()
* @ORM\GeneratedValue()
* @ORM\Column(type="integer")
*/
private int $id;
/**
* @var string
* @ORM\Column(name="name", type="string", length=50, nullable=false)
*/
private string $name;
}
class GroupUser
{
/**
* @var int
*
* @ORM\Id()
* @ORM\GeneratedValue()
* @ORM\Column(type="integer")
*/
private int $id;
/**
* @var Group
* @ORM\ManyToOne(targetEntity="Group", inversedBy="GroupUser")
* @ORM\JoinColumn(name="group_id", referencedColumnName="id", nullable=false)
*/
private Group $group;
/**
* @var string
* @ORM\Column(type="string", length=50, nullable=false)
*/
private string $type;
/**
* @var int
* @ORM\Column(type="integer", nullable=false)
*/
private int $user;
}
And there are two types of users. Admins and Clients. There's a ManyToMany relationship between Group and User. And the property in GroupUser $type is saving the Class of either Admin or Client and the property $user is saving the id.
id | group_id | user | type |
---|---|---|---|
1 | 1 | 1 | Entity\Admin |
2 | 2 | 1 | Entity\Client |
How do I join it using doctrine from the Admin and Client-side? Or maybe someone could point out to some resources how this kind of relationship works on doctrine? As I'm having a hard time googling anything out. I imagine it could be like a conditional leftJoin, but I can't seem to figure it out.
