脚本宝典收集整理的这篇文章主要介绍了php – 在doctrine 2 doc示例中,拥有方和反面是什么,脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
<?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(); } // ... }
我这样读这个注释:
用户被映射为组,所以组是进行连接管理的实体,因此拥有方?
此外,我已经在文档中阅读过:
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).
/** * @ManyToMany(targetEntity="Group",inversedBy="users") * @JoinTable(name="users_groups") */ private $groups;
看看上面,$groups VAR包含与此用户关联的所有组,但如果您注意到属性定义,$groups var具有与以前一样的mappedBy值(mappedBy =“groups”)的相同名称:
/** * @ManyToMany(targetEntity="User",mappedBy="groups") */ private $users;
以上是脚本宝典为你收集整理的php – 在doctrine 2 doc示例中,拥有方和反面是什么全部内容,希望文章能够帮你解决php – 在doctrine 2 doc示例中,拥有方和反面是什么所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。