学说:目标实体无法在(两个捆绑包)中找到
Doctrine: the target-entity cannot be found in (two bundles)
我正在尝试在 Symfony2 中使用 Doctrine 建立 ManyToOne 关系。我的实体是:
namespace My\ApiBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\ArrayCollection;
/**
* @ORM\Entity
* @ORM\Table(name="company")
*/
class Company
{
/**
* @var integer
*
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="IDENTITY")
*/
protected $id;
public function __construct() {
$this->users = new ArrayCollection();
}
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
还有一个:
namespace My\UserBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use FOS\UserBundle\Entity\User as BaseUser;
/**
* User
*
* @ORM\Table(name="user")
* @ORM\Entity
*/
class User extends BaseUser
{
public function __construct()
{
parent::__construct();
}
/**
* @var
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
...
/**
* @ORM\ManyToOne(targetEntity="My\ApiBundle\Entity\Company")
* @ORM\JoinColumn(name="idLastCompany", referencedColumnName="id")
*/
protected $idLastCompany;
显然与其他属性及其设置和获取方法有关,但我唯一的关系是 Company 与 idLastCompany 之间的关系。例如,当我清除缓存时,出现此错误:
MappingException: The target-entity My\ApiBundle\Entity\Copmany cannot
be found in 'My\UserBundle\Entity\User#idLastCompany'.
有什么想法吗?
谢谢
错误消息告诉你你需要的一切:)
MappingException: 在 'My\UserBundle\Entity\User#idLastCompany' 中找不到目标实体 My\ApiBundle\Entity\ Copmany。
您在实体文件名、实体 class 名称或关系字段 $idLastCompany 文档块中拼写了 CoPMany 而不是 Company。
尽管您在此处发布的代码是正确的,但您的实际代码包含错字。
我会在整个项目中搜索 "Copmany" 并修复拼写错误。然后就可以了。
我正在尝试在 Symfony2 中使用 Doctrine 建立 ManyToOne 关系。我的实体是:
namespace My\ApiBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\ArrayCollection;
/**
* @ORM\Entity
* @ORM\Table(name="company")
*/
class Company
{
/**
* @var integer
*
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="IDENTITY")
*/
protected $id;
public function __construct() {
$this->users = new ArrayCollection();
}
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
还有一个:
namespace My\UserBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use FOS\UserBundle\Entity\User as BaseUser;
/**
* User
*
* @ORM\Table(name="user")
* @ORM\Entity
*/
class User extends BaseUser
{
public function __construct()
{
parent::__construct();
}
/**
* @var
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
...
/**
* @ORM\ManyToOne(targetEntity="My\ApiBundle\Entity\Company")
* @ORM\JoinColumn(name="idLastCompany", referencedColumnName="id")
*/
protected $idLastCompany;
显然与其他属性及其设置和获取方法有关,但我唯一的关系是 Company 与 idLastCompany 之间的关系。例如,当我清除缓存时,出现此错误:
MappingException: The target-entity My\ApiBundle\Entity\Copmany cannot be found in 'My\UserBundle\Entity\User#idLastCompany'.
有什么想法吗? 谢谢
错误消息告诉你你需要的一切:)
MappingException: 在 'My\UserBundle\Entity\User#idLastCompany' 中找不到目标实体 My\ApiBundle\Entity\ Copmany。
您在实体文件名、实体 class 名称或关系字段 $idLastCompany 文档块中拼写了 CoPMany 而不是 Company。
尽管您在此处发布的代码是正确的,但您的实际代码包含错字。
我会在整个项目中搜索 "Copmany" 并修复拼写错误。然后就可以了。