Hello I have 2 models Contracts and Services with a relationship. I would like to save several lines of presentation the table looks like this:
array(
'files' => '',
'Contract' => array(
'client_id' => '324',
'residence_id' => '1017',
'name' => '',
'beggin' => '',
'end' => '',
'content1' => '',
'content2' => '',
'content3' => '',
'content4' => '',
'content5' => '',
'content6' => ''
),
'Prestation' => array(
'prestation' => array(
(int) 0 => array(
'zone' => 'Bat A',
'id_prestation' => array(
(int) 0 => '',
(int) 1 => '14'
)
),
(int) 1 => array(
'zone' => 'Bat B',
'id_prestation' => array(
(int) 0 => '',
(int) 1 => '10',
(int) 2 => '14'
)
)
)
),
'Statu' => array(
(int) 0 => array(
'status' => 'proposed'
)
)
)
I try to save all the services in the contracts_prestation table which looks like this: prestations
public function add() {
if ($this->request->is(array('post', 'put')))
{
// TODO: Rewrite or remove the two next conditions when client and residences will be re-implemented.
// SUPPRESSION DU CLIENT
if (!empty($this->request->data['Contract']['client_id'])) {
unset($this->request->data['Client']);
} else {
unset($this->request->data['Contract']['client_id']);
}
// SUPPRESSION DE LA RESIDENCE
if (!empty($this->request->data['Contract']['residence_id'])) {
unset($this->request->data['Residence']);
} else {
unset($this->request->data['Contract']['residence_id']);
}
// AJOUT DU STATUS
$this->request->data['Statu'] = array( 0 => array( 'status' => 'proposed' ) );
// AJOUT DU CONTRAT
$this->Contract->create();
$this->request->data['Contract']['is_active'] = false;
if ($this->Contract->saveAll($this->request->data))
{
$this->Session->setFlash(__('Contrat enregistré.'));
return $this->redirect(array('controller' => 'contracts', 'action' => 'index'));
}
$this->Session->setFlash(__("Impossible d'enregistrer le devis."));
}
else
{
$this->set( 'clients', $this->Client->find('list') );
$this->set( 'residences', $this->Residence->find('list') );
$this->set( 'prestations', $this->Prestation->find('list') );
}
}
I can't seem to find where is the problem with my relationship?
Do you think I forgot something? Thank you for your help.