【发布时间】:2017-05-08 22:49:58
【问题描述】:
我有两个实体,Match 和 Team,问题在于映射(我猜),我不是在找人来解决这个问题,只是给我一些提示,我应该在哪里查看文档。出于某种原因,我陷入了困境,找不到解决方案。我将提供我的两个实体的代码。 匹配.php
/**
* @var
* @ORM\ManyToOne(targetEntity="AppBundle\Entity\Team", inversedBy="matchOne")
* @ORM\JoinColumn(name="team_one_id", referencedColumnName="id")
*/
protected $teamOne;
/**
* @var
* @ORM\ManyToOne(targetEntity="AppBundle\Entity\Team", inversedBy="matchTwo")
* @ORM\JoinColumn(name="team_two_id", referencedColumnName="id")
*/
protected $teamTwo;
团队.php
/**
* @var
* @ORM\OneToMany(targetEntity="AppBundle\Entity\Match", mappedBy="teamOne")
*/
protected $matchOne;
/**
* @var
* @ORM\OneToMany(targetEntity="AppBundle\Entity\Match", mappedBy="teamTwo")
*/
protected $matchTwo;
当我查询匹配时,问题出在我的表单类型中,这是代码的一部分
->add('match', EntityType::class, [
'class' => 'AppBundle:Match',
'choice_label' => 'getMatch',
] )
还有getMatch函数
public function getMatch() {
return $this->getTeamOne()->getName() . ' - ' . $this->getTeamTwo()->getName();
}
表单类型用于创建新投注,显然我想在下拉列表中显示比赛(球队名称,例如:切尔西 - 利物浦)并将该比赛的 id 写入投注实体。
【问题讨论】:
标签: php symfony doctrine-orm symfony-2.8