this is a really naive approach, nonetheless, this could be helpful.
It will only work if the property is actually type hinted with Doctrine\Common\Collections\Collection.
It won't create an ArrayCollection if the property is only type hinted with phpdoc, or if it has a complex type hint (for instance, I saw in few occasions something like private array|Collection $relations).
Another cleaner approach would have been to use doctrine metadata in Hydrator but this seemed convoluted.
But I think the current implementation is good enough for now, since the type hint with Collection is how it is documented by Doctrine.
Maybe in the future we might support other \Traversable objects?
please review https://github.com/zenstruck/foundry/pull/653 before, as this PR is built is the top of the other
fixes https://github.com/zenstruck/foundry/issues/474
this is a really naive approach, nonetheless, this could be helpful. It will only work if the property is actually type hinted with
Doctrine\Common\Collections\Collection
. It won't create anArrayCollection
if the property is only type hinted with phpdoc, or if it has a complex type hint (for instance, I saw in few occasions something likeprivate array|Collection $relations
).Another cleaner approach would have been to use doctrine metadata in
Hydrator
but this seemed convoluted.But I think the current implementation is good enough for now, since the type hint with
Collection
is how it is documented by Doctrine.Maybe in the future we might support other
\Traversable
objects?