I am working on a custom ancestry-chain hydrator which hydrates Root
entities (see entity excerpt below). It works quite well. The hydrator gets its entities from Doctrine and works on them. The hydrator then returns what it has worked as actual result.
So now the hydrator requires a property in the entity called leaves
to store ancestors. I imagined the below property setup would work, and that I would get an empty initialized leaves
property when Doctrine is bringing Root
entities from the database to the hydrator, then the hydrator would just store in their leaves
the objects it has determined to be ancestors for further processing.
The property has to be initialized with an empty Doctrine ArrayCollection
(unmapped). So I added it and... nothing. It doesn't get initialized. Mapped associations collections however, work.
Is there some switch, declaration or standard one has to adhere to? Or what should I do to make Doctrine initialize it?
class Root
{
...
/**
* @var Collection
*/
public Collection $leaves;
/**
* @ORM\OneToMany(targetEntity="Root", mappedBy="parent", fetch="EXTRA_LAZY", indexBy="id")
*/
private Collection $children;
/**
* @throws Exception
*/
public function __construct()
{
$this->leaves=new ArrayCollection(); <- no effect
$this->children=new ArrayCollection(); <- is initialized
}
...
}