Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"targetEntity" from another bundle in Symfony2.3

I would like to use an entity in another bundle "targetEntity" property but it generated error...

Between this class :

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;

And this one :

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;

When I run line command :

sf doctrine:schema:update --force

I get :

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

Any suggestions ?

like image 964
apsylone Avatar asked Jul 26 '13 17:07

apsylone


1 Answers

You mispelled bundle in a few places:

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

...and here:

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

Replace BlogBunble by BlogBundle and CoreBunble by CoreBundle

like image 197
Pier-Luc Gendreau Avatar answered Sep 21 '22 03:09

Pier-Luc Gendreau