我是CakePHP的新手,对关联等方面还不太了解。当我想要删除一个类别时,我也希望能删除与该类别相关联的能力。这是我的表模型:
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中的能力。我知道我忘了什么,但无法想出是什么。