5

我想在另一个包“targetEntity”属性中使用一个实体,但它产生了错误......

在这个类之间:

namespace Tgb\CoreBundle\Entity;

use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;
use Symfony\Component\Validator\Constraints as Assert;

/**
 * Website
 *
 * @ORM\Table(name="core_website")
 * @ORM\Entity(repositoryClass="Tgb\CoreBundle\Entity\WebsiteRepository")
 */
class Website
{

    /**
     * @var Tgb\BlogBunble\Entity\Blog
     *
     * @ORM\OneToOne(targetEntity="Tgb\BlogBunble\Entity\Blog", mappedBy="website")
     */
    private $blog;

和这个 :

namespace Tgb\BlogBundle\Entity;

use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;
use Symfony\Component\Validator\Constraints as Assert;

/**
 * Blog
 *
 * @ORM\Table(name="blog")
 * @ORM\Entity(repositoryClass="Tgb\BlogBundle\Entity\BlogRepository")
 */
class Blog
{

    /**
     * @var Tgb\CoreBunble\Entity\Website
     *
     * @ORM\OneToOne(targetEntity="Tgb\CoreBunble\Entity\Website", inversedBy="blog", cascade={"persist", "merge"})
     */
    private $website;

当我运行 line 命令时:

sf doctrine:schema:update --force

我得到:

[Doctrine\ORM\Mapping\MappingException]                                                                
  The target-entity Tgb\BlogBunble\Entity\Blog cannot be found in 'Tgb\CoreBundle\Entity\Website#blog'.  

有什么建议么 ?

4

1 回答 1

6

您在几个地方拼错了 bundle:

   /**
     * @var Tgb\BlogBunble\Entity\Blog
     *
     * @ORM\OneToOne(targetEntity="Tgb\BlogBunble\Entity\Blog", mappedBy="website")
     */
    private $blog;

...和这里:

    /**
     * @var Tgb\CoreBunble\Entity\Website
     *
     * @ORM\OneToOne(targetEntity="Tgb\CoreBunble\Entity\Website", inversedBy="blog", cascade={"persist", "merge"})
     */
    private $website;

替换BlogBunbleBlogBundle_ CoreBunble_CoreBundle

于 2013-07-26T21:55:06.183 回答