I am trying to embedd a form with a collection type (one to one relation) but I get the error:
Expected argument of type "App\Entity\PatientsSafeData", "array" given at property path "patiPatientsSafeData".
In the entity Patient
<?php
namespace App\Entity;
use App\Repository\PatientsRepository;
use Doctrine\ORM\Mapping as ORM;
class Patients
{
private $id;
private $patiLabel;
/**
* @ORM\OneToOne(targetEntity=PatientsSafeData::class, mappedBy="pasaPatient", cascade={"persist", "remove"})
*/
private $patiPatientsSafeData;
And the entity PatientsSafeData
<?php
namespace App\Entity;
use App\Repository\PatientsSafeDataRepository;
use Doctrine\ORM\Mapping as ORM;
class PatientsSafeData
{
private $id;
/**
* @ORM\OneToOne(targetEntity=Patients::class, inversedBy="patiPatientsSafeData", cascade={"persist", "remove"})
* @ORM\JoinColumn(nullable=false)
*/
private $pasaPatient;
The formType
<?php
namespace App\Form;
use App\Form\PatientsSafeDataType;
use App\Entity\Patients;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\CollectionType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Form\Extension\Core\Type\TextType;
class PatientsType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('patiLabel',TextType::class, ["label" => "Label"])
->add('patiPatientsSafeData' , CollectionType::class,
[
'entry_type' => PatientsSafeDataType::class,
'entry_options' => ['label' => 'Safe Data'],
'allow_add' => true
])
The template:
<div class="card-body">
<p>Save Data</p>
<p>
<ul class="safeData" id="safeData" data-prototype="{{ form_widget(form.patiPatientsSafeData.vars.prototype)|e('html_attr') }}">
{% for patSafeData in form.patiPatientsSafeData %}
<li>
{{ form_row(patSafeData.pasaName) }}
{{ form_row(patSafeData.pasaSurname) }}
{{ form_row(patSafeData.pasaDOB) }}
</li>
{% endfor %}
</ul>
</p>
</div>
I get the error saving data. I dont know where I am wrong, Please, any idea? Thanks in advance