0
I made a panel with some functions of Tree, edit, move and delete. Until then my erasing is working when I want to erase a specific thing without children. The problem is that when I delete an item that has children, it erases all the children together, and my intention was that it would change the parent_id of the children from the item that will be deleted, to the item that I selected in the list.
PS: that $this->request->data['Navigation']['childs']
is the id I have a menu with a list returning all the ids I have available so that the person can change them.
public function apagar($id){
if ($this->request->is('post')){
empty($this->request->data['Navigation']['childs']) ? null : $this->request->data['Navigation']['childs'];
$this->Navigation->updateAll(array(
'Navigation.parent_id' => $id,
), array(
'Navigation.parent_id' => $this->request->data['Navigation']['childs'],
));
$this->Navigation->id = $id;
$this->Navigation->delete();
$this->Session->setFlash('Menu Apagado!');
return $this->redirect('/navegacao');
} else {
$tree = $this->Navigation->generateTreeList(null, null, null, ' - ');
unset($tree[$id]);
$this->set('tree', $tree);
}
}
It changes the parent_id, but it doesn’t delete the id the guy clicks, there are the changed ids, but the id I clicked to delete is still there.
– Roberto Saragoça
Try switching to
$this->Navigation->delete($id)
.– Paulo Rodrigues
I put this, but then, it excludes the id, and his son, IE, ends up excluding everything.
– Roberto Saragoça
If you are updating relationship ids before deleting, you have no reason to delete these children as well. In his Model, where this relationship was declared, the property
dependent
is defined as false?– Paulo Rodrigues
My model is just like this:
public $useTable = 'navigation';
 
 public $displayField = 'nome';
 
 public $actsAs = array('Tree');
I really don’t understand why when I delete id, it deletes all parents_id that is related to it.– Roberto Saragoça