4

我正在使用 Symfony 2.3,当我尝试列出项目时出现此异常:

The target-entity Weber\ProjectBundle\Entity\SurveyUrl cannot be found in 'Weber\ProjectBundle\Entity\Project#surveyUrls'.

我的实体的简化是:

项目.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;
    }
}

受访者.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 实体之前完全没有问题,而且两个实体的配置几乎相同。

谢谢你的帮助。

4

1 回答 1

6

您的项目实体中有错误:

/**
 * @ORM\OneToMany(targetEntity="SurveyUrl", mappedBy="project")
 */
protected $surveyUrls;

targetEntity="SurveyUrl" 必须替换为 targetEntity="SurveyURL"

您必须匹配您的实体案例

于 2013-07-05T15:42:31.573 回答