来自Symfony2.3中另一个包的“targetEntity”

时间:2013-07-26 17:23:51

标签: symfony doctrine-orm

我想在另一个捆绑“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'.  

有什么建议吗?

1 个答案:

答案 0 :(得分:6)

你在几个地方拼错了包裹:

   /**
     * @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;

BlogBunble改为BlogBundle而将CoreBunble改为CoreBundle