I’ve got symfony form with CollectionType. It’s a multistep form and when im dumping data after each step it saves properly:
AppEntityRezylientnaArchitektura {#654 ▼
-id: null
-BezpInf: DoctrineCommonCollectionsArrayCollection {#655 ▼
-elements: array:1 [▼
0 => array:3 [▼
"BezpInf_1" => "0"
"BezpInf_2" => "1"
"BezpInf_3" => "1"
]
]
}
-useruuid: "ea9ae76e-b688-11ed-be51-494b48375171"
Form:
$builder->add('useruuid', HiddenType::class, [
'data' => $this->getUserUUID(),
]);
$builder->add('BezpInf', CollectionType::class, [
'entry_type' => AnswersTempType::class,
'allow_extra_fields' => true,
'entry_options' => [
'label' => false,
],
'label' => false,
// 'by_reference' => false,
]);
Entity:
#[ORMEntity(repositoryClass: RezylientnaArchitekturaRepository::class)]
class RezylientnaArchitektura
{
#[ORMId]
#[ORMGeneratedValue]
#[ORMColumn]
private ?int $id = null;
#[ORMColumn(length: 255)]
private $BezpInf = null;
#[ORMColumn(length: 255)]
private ?string $useruuid = null;
public function __construct()
{
$this->BezpInf = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getBezpInf(): Collection
{
return $this->BezpInf;
}
public function setBezpInf(string $BezpInf): self
{
$this->BezpInf = $BezpInf;
return $this;
}
public function getUseruuid(): ?string
{
return $this->useruuid;
}
public function setUseruuid(string $useruuid): self
{
$this->useruuid = $useruuid;
return $this;
}
}
And now tricky part. When i want to save it into db in classic way:
// ...
$em = $this->doctrine->getManager();
$em->persist($answer);
$em->flush();
// ...
it saves like:
| id | bezpinf | useruuid |
|---|---|---|
| ….. | DoctrineCommonCollectionsArrayCollection@000000000000032f0000000000000000 | ….. |
When i add to a form
'by_reference' => false
it render in a dump – DoctrineCommonCollectionsArrayCollection@000000000000032f0000000000000000 and save the same.
How can i persist my arraycollection into db properly?