I'm having trouble updating more of the model in the same form in cakephp, I've done several different modes and in all the main model is inserted / updated because the related model does not.
My controller looks like this:
$this->loadModel('Jobs');
$campanha = $this->Campanhas->newEntity();
$jobs = $this->Jobs->newEntity();
if ($this->request->is('post')) {
$jobs = $this->Jobs->patchEntity($jobs, $this->request->data);
$campanha = $this->Campanhas->patchEntity($campanha, $this->request->data);
$save = $this->Campanhas->save($campanha);
if ($save) {
$jobs['campanha_id'] = $save->id;
$savejob = $this->Job->save($jobs);
if($savejob){
$this->Flash->success(__('The job has been saved.'));
$this->redirect(array('action' => 'index'));
}else{
$this->Flash->success(__('The job hasnt been saved.'));
}
}else {
$this->Flash->error(__('The job hasnt been saved.'));
}
}
However, as I said before, the model data "Campaigns" are inserted, but the "Jobs" model is not.
The form looks like this:
<fieldset>
<legend><?= __('Add Campanha') ?></legend>
<?php
echo $this->Form->input('Campanhas.nome');
echo $this->Form->input('Campanhas.data', ['class' => 'datepicker']);
echo $this->Form->input('Campanhas.cliente_id', ['options' => $cadastros, 'id' => 'cliente_id']);
echo $this->Form->input('Campanhas.contato_id', ['options' => $contatos, 'id' => 'contato_id']);
echo $this->Form->input('Campanhas.requisitante_id', ['options' => $users]);
echo $this->Form->input('Campanhas.briefing');
?>
</fieldset>
<fieldset>
<legend><?= __('Add Job') ?></legend>
<?php
echo $this->Form->input('Jobs.nome');
echo $this->Form->input('Jobs.status_id', ['options' => $status]);
echo $this->Form->input('Jobs.prioridade_id', ['options' => $prioridades]);
echo $this->Form->input('Jobs.iniciar');
echo $this->Form->input('Jobs.concluir');
echo $this->Form->input('Jobs.estimado');
echo $this->Form->input('Jobs.gasto');
echo $this->Form->hidden('Jobs.campanha_id');
?>
</fieldset>
I have checked the variables $jobs
and $campanhas
both are correct and with the data coming from the form, and does not present any error and success, it only saves the campaign and does not save the job.
Any light?