简体   繁体   English

实体依赖Symfony2

[英]Entity dependency Symfony2

I have two bundles with two entity's. 我有两个实体的捆绑。 I need to create a manyToMany relationship between these entity's. 我需要在这些实体之间创建一个manyToMany关系。

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? 有任何想法吗?

According to your Property class definition, you have defined a ManyToMany relation with User . 根据您的Property类定义,您已经定义了与UserManyToMany关系。 As you omitted the namespace, the current one will be used: 当您省略命名空间时,将使用当前的命名空间:

User will be translated to Pfwd\\AdminBundle\\PropertyBundle\\Entity\\User User将被翻译为Pfwd\\AdminBundle\\PropertyBundle\\Entity\\User

You have to specify the FQCN: 您必须指定FQCN:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM