gpt4 book ai didi

php - 实体依赖 Symfony2

转载 作者:搜寻专家 更新时间:2023-10-31 21:14:38 25 4
gpt4 key购买 nike

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

属性:

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 关系。由于您省略了 namespace ,因此将使用当前 namespace :

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

您必须指定 FQCN:

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

关于php - 实体依赖 Symfony2,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11734217/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com