php – Doctrine2 Mapping:映射到一个字段的2个字段(ManyToOne)
我有2个实体,即Match和Team.一个团队可以拥有一对多的比赛.但是,我的Match实体包含两个引用同一实体Team的字段.他们是$homeTeam和$awayTeam.如何将Team,$matches中的相同字段作为双向关系引用?
我目前的非工作代码如下: 我的匹配实体: /** * @ORMEntity * @ORMTable(name="match") **/ class Match { /** * @ORMManyToOne(targetEntity="Team",inversedBy="matches") * @ORMJoinColumn(name="home_team_id",referencedColumnName="id") * **/ protected $homeTeam; /** * @ORMManyToOne(targetEntity="Team",inversedBy="matches") * @ORMJoinColumn(name="away_team_id",referencedColumnName="id") * **/ protected $awayTeam; 我的团队实体(我猜不正确?): /** * @ORMEntity * @ORMTable(name="team") * **/ class Team { /** @ORMOneToMany(targetEntity="Match",mappedBy="homeTeam",mappedBy="awayTeam") **/ protected $matches;
在探索
Doctrine’s official docs之后:您无法添加多个mappedBy列.除此之外,您可以选择:
>为Match创建自定义存储库并定义方法getAllMatchesForTeam($team) 在这里阅读更多: > https://stackoverflow.com/questions/13922047/symfony2-doctrine2-how-to-implement-methods-on-entity-to-retrieve-related-ent (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |