2012-07-31 118 views
3

我有兩個包含兩個實體的包。我需要在這些實體之間創建一個manyToMany關係。實體依賴關係Symfony2

物業:

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 

任何想法?

+2

類文件dind't存在...從你的代碼片斷,這是非常清楚的..你可以粘貼你的Pfwd \ AdminBundle \ PropertyBundle \ Entity \ drectory的'ls'嗎? – DonCallisto 2012-07-31 07:23:28

回答

2

根據您的Property類別定義,您已定義與UserManyToMany關係。當你省略了命名空間,目前的一個將被使用:

User將被轉換爲Pfwd\AdminBundle\PropertyBundle\Entity\User

您必須指定FQCN:

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