cakephp中的deleteAll问题..

时间:2012-04-07 10:49:29

标签: cakephp-2.0

我正在使用cakephp 2.0。使用delete All功能。我没有从DB中删除任何错误。

public function admin_deleteTutorial($tutorial_id = null){
    if($tutorial_id > 0){
        //          $this->Tutorial->delete($tutorial_id);

        $condition = array('TutorialDiscussion.tutorial_id' => $tutorial_id );
        $this->TutorialDiscussion->deleteAll($condition);

        $this->Session->write('message','Tutorial details deleted successfully.');
        $this->redirect('/admin/tutorials/index/');

    }
}


** Is it required to first find out list of all id's from TutorialDiscussion having tutoril id this $tutorial. or it will delete all itself.** Though records are deleted from TUtorials so I have commented that.

2 个答案:

答案 0 :(得分:1)

尝试将$cascade设置为第二个参数为true。因此,如果模型中的dependent也设置为true,则所有相关记录也会被删除。

dependent cascade

答案 1 :(得分:0)

试试这个

$this->TutorialDiscussion->deleteAll($condition,false);