3

我有两个包含两个实体的捆绑包。我需要在这些实体之间创建多对多关系。

财产:

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;

//..

用户:

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;

   // ...

属性包依赖于用户包。

当我跑

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

我收到以下错误:

 [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   

有任何想法吗?

4

1 回答 1

2

根据您的Property类定义,您已经定义了与 的ManyToMany关系User。由于您省略了命名空间,因此将使用当前命名空间:

User将被翻译成Pfwd\AdminBundle\PropertyBundle\Entity\User

您必须指定 FQCN:

@ORM\ManyToMany(targetEntity="Pfwd\UserBundle\Entity\User")
于 2012-07-31T08:23:57.130 回答