我有带有 CollectionType 的 symfony 形式。这是一个多步骤表单,当我在每一步后转储数据时,它会正确保存:
App\Entity\RezylientnaArchitektura {#654 ▼
-id: null
-BezpInf: Doctrine\Common\Collections\ArrayCollection {#655 ▼
-elements: array:1 [▼
0 => array:3 [▼
"BezpInf_1" => "0"
"BezpInf_2" => "1"
"BezpInf_3" => "1"
]
]
}
-useruuid: "ea9ae76e-b688-11ed-be51-494b48375171"
形式:
$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,
]);
实体:
#[ORM\Entity(repositoryClass: RezylientnaArchitekturaRepository::class)]
class RezylientnaArchitektura
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
private ?int $id = null;
#[ORM\Column(length: 255)]
private $BezpInf = null;
#[ORM\Column(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;
}
}
现在是棘手的部分。当我想以经典方式将其保存到数据库中时:
// ...
$em = $this->doctrine->getManager();
$em->persist($answer);
$em->flush();
// ...
它保存如下:
id | bezpinf | 用户uuid |
---|---|---|
…… | 学说\通用\集合\数组集合@000000000000032f00000000000000000000000000000000000000000 |
'by_reference' => false
它呈现在转储中 - Doctrine\Common\Collections\ArrayCollection@000000000000032f0000000000000000 并保存相同的内容。我怎样才能正确地将我的 arraycollection 保存到数据库中?