0
votes

I can not get the "Contact" data displayed in the Edit form. In the Edit view, it shows me the Volunteers and People data, but not the contacts data. To bring the data, I must change "echo $ this-> Form-> input ('direccion');" by echo $ this-> Form-> input ('persona.contacto.direccion'); but by doing this the contact form is not saved. What is the solution?

In my form

echo $this->Form->input('direccion'); echo $this->Form->input('persona.nombre'); echo $this->Form->input('persona.voluntario.cv');

In my function edit controller

$particulare = $this->Particulares->get($id, [
        'contain' => ['Voluntarios','Beneficiarios','Personas'=>['Contactos'=>['Paises','Provincias','Localidades']]]
    ]);


    if ($this->request->is(['patch', 'post', 'put'])) {
        $particulare = $this->Particulares->patchEntity($particulare, $this->request->getData());


        if ($this->Particulares->save($particulare)) {
            $this->Flash->success(__('Éxito! Los cambios han sido guardados correctamente'));

            return $this->redirect(['action' => 'index']);
        }
        $this->Flash->error(__('Los cambios no pudieron ser guardados. Por favor, inténtelo de nuevo.'));
    }
1

1 Answers

0
votes

As the manual says, "By default the save() method will also save one level of associations". You're trying to save a second level of associations, so "When building forms that save nested associations, you need to define which associations should be marshalled". So, your patch statement should look more like this:

$particulare = $this->Particulares->patchEntity($particulare, $this->request->getData(),
    'associated' => ['Voluntarios', 'Personas.Contactos']
);