How to change the field of a table, taking values from another table as a reference. Using cakephp 1.3

1

I have an association of tables projeto > auto > anexo . In the project table I have a field cod_status , and in the attached table I have a field status . How do I make the Anexo.status change to Projeto.cod_status automatically when I edit the field 5 to 'I'.

Controller Edit

   function edit($id = null)
{
    if (!$id && empty($this->data)) {
        $this->Session->setFlash(sprintf(__('%s inválido.', true), 'Anexo'));
        $this->redirect(array('action' => 'index'));
    }
    if (!empty($this->data)) {
        if ($this->Anexo->save($this->data)) {
            $this->Session->setFlash(sprintf(__('%s alterado com sucesso.', true), 'Anexo'), 'default', array('class' => 'success'));
            $this->redirect(array('action' => 'index'));
        } else {
            $this->Session->setFlash(sprintf(__('O %s não pode ser salvo. Por favor, tente novamente.', true), 'anexo'));
        }
    }
    if (empty($this->data)) {
        $this->data = $this->Anexo->read(null, $id);
    }
}
    
asked by anonymous 18.12.2017 / 03:35

1 answer

0

Just checking if the data to save your field has the desired value and make a condition so that if it is, save the Project also, I believe it works:

Within your if ($this->Anexo->save($this->data)) { enter the following code as the operation I mentioned above.

if ($this->data['status'] === 'l'){
  $this->Projeto->set(array('cod_status' => 5));
  $this->Projeto->save();
}

Maybe the data format in $this->Data is different from just an array with the fields of the template in question, and if it is, please debug and change to fit this format, it might be something like $this->data['Anexo']['status'] too .

    
18.12.2017 / 11:35