我有两个实体,分组和用户:
class Group
{
/**
* @ORM\ManyToMany(targetEntity="Group", inversedBy="groups")
* @ORM\JoinTable(name="admin_group_user",
* joinColumns={@ORM\JoinColumn(name="fk_group", referencedColumnName="id")},
* inverseJoinColumns={@ORM\JoinColumn(name="fk_user", referencedColumnName="id")}
* )
*/
protected $users;
...
}
class User
{
/**
* @ORM\ManyToMany(targetEntity="Group", inversedBy="users")
* @ORM\JoinTable(name="admin_group_user",
* joinColumns={@ORM\JoinColumn(name="fk_user", referencedColumnName="id")},
* inverseJoinColumns={@ORM\JoinColumn(name="fk_group", referencedColumnName="id")}
* )
*/
protected $groups;
...
}
我想获得结果 组1具有用户A,用户B,用户C. 组2具有用户D,用户E,用户F.
通常类似
SELECT admin_group.id AS group_id, admin_group.name, agu.fk_user, fu.username
FROM admin_group
JOIN admin_group_user agu ON (admin_group.id = agu.fk_group)
JOIN front_user fu ON (agu.fk_user = fu.id);
有人知道如何使用Doctrine实现这一目标吗?
答案 0 :(得分:1)
关于doctrine上的多对多双向映射的文档可帮助您解决问题: