首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >CakePHP 3汇编删除

CakePHP 3汇编删除
EN

Stack Overflow用户
提问于 2017-01-17 17:49:04
回答 1查看 63关注 0票数 4

我对CakePHP和所有这些与联想有关的东西都很陌生。当我想要删除一个类别时,我也要删除链接到该类别的权限。这是我的桌子模型:

CategoriesTable.php

代码语言:javascript
复制
class CategoriesTable extends Table
{
    public function initialize(array $config)
    {
        parent::initialize($config);

        $this->belongsToMany('Competences');
    }
}

CompetencesTable.php

代码语言:javascript
复制
class CompetencesTable extends Table
{
     public function initialize(array $config)
     {
        parent::initialize($config);

        $this->belongsToMany('Categories');
        $this->belongsToMany('CategoriesCompetences');
     }
}

CategoriesCompetencesTable.php

代码语言:javascript
复制
class CategoriesCompetencesTable extends Table
{
    public function initialize(array $config)
    {
        parent::initialize($config);

        $this->belongsTo('Categories');
        $this->hasMany('Competences');
    }
}

当我删除一个类别时,它会删除链接表中的行,但不会删除CompetenceTable中的权限。我知道我忘记了一些东西,但我想不出是什么。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-01-18 00:09:34

我不知道为什么您的join表中有一个hasMany assoc。有理由吗?应该是belongsTo。如果没有,请尝试在关联选项dependent => true中设置hasMany assoc。

请参阅hasMany()的文档。仔细阅读整页是个好主意。

代码语言:javascript
复制
public function initialize(array $config)
{
    $this->hasMany('Competences', [
        'foreignKey' => 'article_id',
        'dependent' => true,
    ]);
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/41703741

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档