CakePHP 3关联删除
发布时间:2020-12-13 16:08:45 所属栏目:PHP教程 来源:网络整理
导读:我是Cake PHP的新手,以及所有关联的东西.当我想删除一个类别时,我也想删除链接到该类别的权限.这是我的桌子型号: CategoriesTable.php class CategoriesTable extends Table{ public function initialize(array $config) { parent::initialize($config); $t
我是Cake
PHP的新手,以及所有关联的东西.当我想删除一个类别时,我也想删除链接到该类别的权限.这是我的桌子型号:
CategoriesTable.php class CategoriesTable extends Table { public function initialize(array $config) { parent::initialize($config); $this->belongsToMany('Competences'); } } CompetencesTable.php class CompetencesTable extends Table { public function initialize(array $config) { parent::initialize($config); $this->belongsToMany('Categories'); $this->belongsToMany('CategoriesCompetences'); } } CategoriesCompetencesTable.php class CategoriesCompetencesTable extends Table { public function initialize(array $config) { parent::initialize($config); $this->belongsTo('Categories'); $this->hasMany('Competences'); } } 当我删除一个类别时,它会删除链接表中的行,但不会删除CompetenceTable中的权限.我知道我忘了一些东西,但无法弄清楚是什么. 解决方法
我不确定为什么你的连接表中有一个hasMany assoc和Competences.有原因吗?它应该属于.如果没有尝试设置依赖关联选项=>如果是hasMany assoc,则为true.
See the documentation for hasMany().仔细阅读整个页面是个好主意. public function initialize(array $config) { $this->hasMany('Competences',[ 'foreignKey' => 'article_id','dependent' => true,]); } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |