【发布时间】:2013-06-25 17:29:12
【问题描述】:
每当我将 ArrayCollection 与 Doctrine ORM(2.3,PHP > 5.4)一起使用,并将对象值与集合中的键相关联(例如使用 set 方法时),值都会正确存储在数据库中.但是当我想从实体中检索集合时,键不会被检索,而是使用数字索引。
例如,如果我有以下课程:
/** @Entity */
class MyEntity
{
/** @OneToMany(targetEntity="MyOtherEntity", mappedBy="mainEntity") */
private $myArray;
public function __construct()
{
$this->myArray = new ArrayCollection();
}
public function addOtherEntity($key, $value)
{
$this->myArray->set($key, $value);
}
...
}
/** @Entity */
class MyOtherEntity
{
/** @ManyToOne(targetEntity="MyEntity", inversedBy="myArray") */
private $mainEntity;
...
}
set 方法可以正常工作,但是当我检索信息时,$myArray 中的键消失了。
如何让 ORM 正确记住密钥?提前谢谢你。
【问题讨论】:
标签: php orm doctrine-orm