7
Doctrine ORM (2.3, PHP> 5.4)과 함께 ArrayCollection을 사용하고 객체 값을 (예 : set
메서드를 사용할 때) 컬렉션의 키와 연결할 때마다 값이 올바르게 저장됩니다 데이터베이스에. 그러나 엔터티에서 컬렉션을 검색하려면 키가 검색되지 않고 대신 숫자 인덱스가 사용됩니다. 예를 들어Doctrine - Store ArrayCollection keys
, 나는 다음과 같은 클래스가있는 경우 :
/** @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이 키를 올바르게 기억하게 할 수 있습니까? 미리 감사드립니다.
응답을 키 생성하는 솔루션입니다. –
http://doctrine-orm.readthedocs.org/ko/latest/tutorials/working-with-indexed-associations.html –
응답을 기다리시겠습니까? 질문 하나? –