我有一个小问题。我有一个Cakephp 3.6项目。一切正常,但是当我想删除一个控制器中的记录时,显示错误。
无法提交事务-嵌套事务中已经调用rollback() Cake \ Database \ Exception \ NestedTransactionRollbackException
蛋糕\ ORM \表->删除
APP / Controller \ NewsController.php,第131行
这是我在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']);
}
并且错误会在上突出显示,如果($ this-> News-> delete($ news)){
我该怎么办?
答案 0 :(得分:3)
默认情况下,所有删除都在事务内发生。您如何通过atomic
禁用交易?
喜欢的事物
$this->News->delete($news, ['atomic' => false]);