在关联映射的这个页面上,manytomany 部分中有一个示例。但我不明白哪个实体(组或用户)是拥有方。
我也把代码放在这里
<?php
/** @Entity */
class User
{
// ...
/**
* @ManyToMany(targetEntity="Group", inversedBy="users")
* @JoinTable(name="users_groups")
*/
private $groups;
public function __construct() {
$this->groups = new \Doctrine\Common\Collections\ArrayCollection();
}
// ...
}
/** @Entity */
class Group
{
// ...
/**
* @ManyToMany(targetEntity="User", mappedBy="groups")
*/
private $users;
public function __construct() {
$this->users = new \Doctrine\Common\Collections\ArrayCollection();
}
// ...
}
我是否像这样阅读此注释: User is mappedBy groups so group 是进行连接管理的实体,因此是拥有方?
另外,我在文档中读过这个:
For ManyToMany bidirectional relationships either side may be the owning side (the side that defines the @JoinTable and/or does not make use of the mappedBy attribute, thus using a default join table).
这让我认为 User 将是拥有方,因为 JoinTable 注释是在该实体中定义的。