pfwd
pfwd

Reputation: 1168

Entity dependency Symfony2

I have two bundles with two entity’s. I need to create a manyToMany relationship between these entity’s.

Property:

namespace Pfwd\AdminBundle\PropertyBundle\Entity;

use Pfwd\UserBundle\Entity\User as User;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;

/**
 * @ORM\Entity
 * @ORM\Table(name="property")
 */
class Property {

//...
/**
 * @ORM\ManyToMany(targetEntity="User")
 * @ORM\JoinTable(name="user_role",
 *     joinColumns={@ORM\JoinColumn(name="user_id", referencedColumnName="id")},
 *     inverseJoinColumns={@ORM\JoinColumn(name="property_id", referencedColumnName="id")}
 * )
 *
 * @var ArrayCollection $salesAgents
 */
protected $salesAgents;

//..

User:

namespace Pfwd\UserBundle\Entity;

use Doctrine\Common\Collections\ArrayCollection;
use Symfony\Component\Security\Core\User\UserInterface;
use Doctrine\ORM\Mapping as ORM;

/**
 * @ORM\Entity
 * @ORM\Table(name="user")
 */
class User implements UserInterface
{
    /**
     * @ORM\Id
     * @ORM\Column(type="integer")
     * @ORM\GeneratedValue(strategy="AUTO")
     * 
     * @var integer $id
     */
    protected $id;

   // ...

The property bundle depends on the user bundle.

When I run

 php app/console doctrine:schema:update --force

I get the following error:

 [ErrorException]                                                             
Warning: class_parents(): Class Pfwd\AdminBundle\PropertyBundle\Entity\User  
does not exist and could not be loaded in <SITE_PATH>/symfony2/vendor/doctrine/lib/Doctrine/ORM/Mapping/Cl  
assMetadataFactory.php line 223   

Any ideas?

Upvotes: 3

Views: 979

Answers (1)

Florent
Florent

Reputation: 12420

According to your Property class definition, you have defined a ManyToMany relation with User. As you omitted the namespace, the current one will be used:

User will be translated to Pfwd\AdminBundle\PropertyBundle\Entity\User

You have to specify the FQCN:

@ORM\ManyToMany(targetEntity="Pfwd\UserBundle\Entity\User")

Upvotes: 2

Related Questions