php - Doctrine doesn't store ArrayCollection -
php - Doctrine doesn't store ArrayCollection -
i have entity
has array field this:
... /** * @var array * * @orm\column(name="tels", type="json_array") */ private $tels; ...
i fill using form , fills correctly after submit var_dump($entity->gettels())
returns this:
object(doctrine\common\collections\arraycollection)[448] private '_elements' => array (size=1) 0 => string '123' (length=3)
but after persist doctrine ignores fields value , stores empty array:
+----+------+ | id | tels | +----+------+ | 1 | {} | +----+------+
what problem?
the type json_array
expects array converted json using json_encode. while doctrine arraycollection technically traversable doesnt nicely cast array. either need phone call ->toarray()
on or alter type array
$entity->settels($thearraycollection->toarray());
php symfony2 doctrine2 arraycollection
Comments
Post a Comment