对不起我的英语...... 我有两个模式:用户和注意 在user.php的:CakePHP的级联删除不工作
var $hasMany=array('Note'=>array('className'=>'Note',
'foreignKey'=>'user_id',
'dependent'=>'true',
'exclusive'=>'true'
)
);
在users_controller.php中:
function delete($id = null) {
if (!$id) {
$this->Session->setFlash(__('Invalid id for User', true));
$this->redirect(array('action'=>'index'));
}
if ($this->User->delete($id,true)) {
$this->Session->setFlash(__('User deleted', true));
$this->redirect(array('action'=>'index'));
}
}
但是,当我删除一个用户,与用户相关的笔记不会被消除!
什么是错?
此代码看起来不错。您的关联和您的delete()方法调用看起来都非常完美,可以处理级联删除关联数据。 – Predominant 2012-08-08 23:46:43