1

I have a little problem. I have a Cakephp 3.6 project. All work fine, but when I want to delete a record in one controller show my a error.

Cannot commit transaction - rollback() has been already called in the nested transaction Cake\Database\Exception\NestedTransactionRollbackException

Cake\ORM\Table->delete
APP/Controller\NewsController.php, line 131

This is my delete action in NewsController.php

public function delete($id = null)
{
    $this->request->allowMethod(['post', 'delete']);
    $news = $this->News->get($id);
    if ($this->News->delete($news)) {
        $this->Flash->success(__('The news has been deleted.'));
    } else {
        $this->Flash->error(__('The news could not be deleted. Please, try again.'));
    }

    return $this->redirect(['action' => 'index']);
}

And the error is highlighted on if ($this->News->delete($news)) {

What can I do ?

l3nox
  • 15
  • 2
  • 8

1 Answers1

8

By default all deletes happen within a transaction. How about you disable the transaction with the atomic?

Something likes

$this->News->delete($news, ['atomic' => false]);

502_Geek
  • 2,046
  • 2
  • 22
  • 32