因此,我试图在Symfony2中与Doctrine建立一对一的关系,但我得到了以下错误:
在模板的呈现过程中抛出了一个异常(在第65行的"IntoPeople\DatabaseBundle\Entity\Feedbackcycle"")类IntoPeopleDatabaseBundle:Feedbackcycle:index.html.twig中“无法解析”列的"id“类型)。
我有两个实体,反馈循环和CDP。在反馈周期,我有:
/**
* @var \IntoPeople\DatabaseBundle\Entity\Cdp
*
* @ORM\OneToOne(targetEntity="IntoPeople\DatabaseBundle\Entity\Cdp", inversedBy="feedbackcycle")
* @ORM\JoinColumns({
* @ORM\JoinColumn(name="CDPId", referencedColumnName="Id")
* })
*/
private $cdp;
/**
* Set cdp
*
* @param \IntoPeople\DatabaseBundle\Entity\Cdp $cdp
*
* @return Feedbackcycle
*/
public function setCdp(\IntoPeople\DatabaseBundle\Entity\Cdp $cdp = null)
{
$this->cdp = $cdp;
return $this;
}
/**
* Get cdp
*
* @return \IntoPeople\DatabaseBundle\Entity\Cdp
*/
public function getCdp()
{
return $this->cdp;
}在CDP中,我有:
/**
* @ORM\OneToOne(targetEntity="Feedbackcycle")
*/
protected $feedbackcycle;
/**
* Set feedbackcycle
*
* @param \IntoPeople\DatabaseBundle\Entity\Feedbackcycle $feedbackcycle
*
* @return Cdp
*/
public function setFeedbackcycle(\IntoPeople\DatabaseBundle\Entity\Feedbackcycle $feedbackcycle = null)
{
$this->feedbackcycle = $feedbackcycle;
return $this;
}
/**
* Get feedbackcycle
*
* @return \IntoPeople\DatabaseBundle\Entity\Feedbackcycle
*/
public function getFeedbackcycle()
{
return $this->feedbackcycle;
}所以,在我的小树枝上,我可以这样做:
{{ feedbackcycle.cdp.id }}这是可行的,或者我也可以做feedbackcycle.name (任何属性),而且它也能工作。但当我做的时候
{{ feedbackcycle.cdp.*ANOTHER ATTRIBUTE* }}我会得到错误的。
发布于 2015-07-27 11:53:58
解决后,我忘了用CDP编写mappedBy:
/**
* @ORM\OneToOne(targetEntity="Feedbackcycle", mappedBy="cdp")
*/
protected $feedbackcycle;https://stackoverflow.com/questions/31652008
复制相似问题