【发布时间】:2014-08-16 12:18:15
【问题描述】:
我在 Symfony 中使用 Doctrine2,我有以下设置:
一个项目类:
/**
* Class Item
*
* @ORM\Table()
* @ORM\Entity(repositoryClass="OneShortly\CommonBundle\Entity\ItemRepository")
*/
class Item
{
/**
* @ORM\ManyToOne(targetEntity="Category")
* @ORM\JoinColumn(name="primaryCategory", referencedColumnName="foreignId")
*/
private $primaryCategory;
}
还有一个 Category 类:
/**
* Category
*
* @ORM\Table()
* @ORM\Entity(repositoryClass="OneShortly\CommonBundle\Entity\CategoryRepository")
*/
class Category
{
/**
* @var integer
*
* @ORM\Column(name="foreignId", type="integer", unique=true)
*/
private $foreignId;
}
现在当我这样做时:
$item = new Item();
$item->setPrimaryCategory($category);
$this->em->persist($item);
$this->em->flush();
我收到此错误:
[Symfony\Component\Debug\Exception\ContextErrorException] 注意: 未定义索引:foreignId in 主页/www/project/vendor/doctrine/orm/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php 第 692 行
现在,我从各个角度查看了这个问题,但仍然看不出这段代码有什么问题。你能帮忙吗?
【问题讨论】:
标签: php symfony doctrine-orm annotations