我正在使用Symfony 2.3,当我尝试列出项目时,我遇到了这个异常:
The target-entity Weber\ProjectBundle\Entity\SurveyUrl cannot be found in 'Weber\ProjectBundle\Entity\Project#surveyUrls'.
我的实体的简化是:
Project.php:
<?php
namespace Weber\ProjectBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\ArrayCollection;
/**
* Project
*
* @ORM\Entity
*/
class Project
{
/**
* @var integer
*
* @ORM\Id
* @ORM\Column(name="id", type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @ORM\OneToMany(targetEntity="Respondent", mappedBy="project")
*/
protected $respondents;
/**
* @ORM\OneToMany(targetEntity="SurveyUrl", mappedBy="project")
*/
protected $surveyUrls;
/**
* Constructor
*/
public function __construct()
{
$this->respondents = new ArrayCollection();
$this->surveyUrls = new ArrayCollection();
}
/**
* Add respondents
*
* @param \Weber\ProjectBundle\Entity\Respondent $respondents
* @return Project
*/
public function addRespondent(\Weber\ProjectBundle\Entity\Respondent $respondents)
{
$this->respondents[] = $respondents;
return $this;
}
/**
* Remove respondents
*
* @param \Weber\ProjectBundle\Entity\Respondent $respondents
*/
public function removeRespondent(\Weber\ProjectBundle\Entity\Respondent $respondents)
{
$this->respondents->removeElement($respondents);
}
/**
* Get respondents
*
* @return \Doctrine\Common\Collections\Collection
*/
public function getRespondents()
{
return $this->respondents;
}
/**
* Add surveyUrls
*
* @param \Weber\ProjectBundle\Entity\SurveyUrl $surveyUrls
* @return Project
*/
public function addSurveyUrl(\Weber\ProjectBundle\Entity\SurveyUrl $surveyUrls)
{
$this->surveyUrls[] = $surveyUrls;
return $this;
}
/**
* Remove surveyUrls
*
* @param \Weber\ProjectBundle\Entity\SurveyUrl $surveyUrls
*/
public function removeSurveyUrl(\Weber\ProjectBundle\Entity\SurveyUrl $surveyUrls)
{
$this->surveyUrls->removeElement($surveyUrls);
}
/**
* Get surveyUrls
*
* @return \Doctrine\Common\Collections\Collection
*/
public function getSurveyUrls()
{
return $this->surveyUrls;
}
}
Respondent.php:
<?php
namespace Weber\ProjectBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* Respondent
*
* @ORM\Entity
*/
class Respondent
{
/**
* @var integer
*
* @ORM\Id
* @ORM\Column(name="id", type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @ORM\ManyToOne(targetEntity="Project")
*/
protected $project;
/**
* Set project
*
* @param \Weber\ProjectBundle\Entity\Project $project
* @return Respondent
*/
public function setProject(\Weber\ProjectBundle\Entity\Project $project = null)
{
$this->project = $project;
return $this;
}
/**
* Get project
*
* @return \Weber\ProjectBundle\Entity\Project
*/
public function getProject()
{
return $this->project;
}
}
和 SurveyUrl.php:
<?php
namespace Weber\ProjectBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* SurveyURL
*
* @ORM\Entity
*/
class SurveyURL
{
/**
* @var integer
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* The project for this url.
*
* @ORM\ManyToOne(targetEntity="Project", inversedBy="surveyUrls")
* (I have also tried without 'inversedBy')
*/
protected $project;
/**
* May be null.
* The respondent that answered this survey.
*
* @ORM\OneToOne(targetEntity="Respondent")
*/
protected $respondent;
/**
* Set project
*
* @param \Weber\ProjectBundle\Entity\Project $project
* @return SurveyURL
*/
public function setProject(\Weber\ProjectBundle\Entity\Project $project = null)
{
$this->project = $project;
return $this;
}
/**
* Get project
*
* @return \Weber\ProjectBundle\Entity\Project
*/
public function getProject()
{
return $this->project;
}
/**
* Set respondent
*
* @param \Weber\ProjectBundle\Entity\Respondent $respondent
* @return SurveyURL
*/
public function setRespondent(\Weber\ProjectBundle\Entity\Respondent $respondent = null)
{
$this->respondent = $respondent;
return $this;
}
/**
* Get respondent
*
* @return \Weber\ProjectBundle\Entity\Respondent
*/
public function getRespondent()
{
return $this->respondent;
}
}
我不明白的是,在创建SurveyUrl实体之前,根本没有任何问题,两个实体的配置几乎相同。
感谢您的帮助。
答案 0 :(得分:5)
您的项目实体中有错误:
/**
* @ORM\OneToMany(targetEntity="SurveyUrl", mappedBy="project")
*/
protected $surveyUrls;
targetEntity =“SurveyUrl”必须替换为targetEntity =“SurveyURL”
您必须匹配您的实体案例