簡體   English   中英

實體依賴Symfony2

[英]Entity dependency Symfony2

我有兩個實體的捆綁。 我需要在這些實體之間創建一個manyToMany關系。

屬性:

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   

有任何想法嗎?

根據您的Property類定義,您已經定義了與UserManyToMany關系。 當您省略命名空間時,將使用當前的命名空間:

User將被翻譯為Pfwd\\AdminBundle\\PropertyBundle\\Entity\\User

您必須指定FQCN:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM