gpt4 book ai didi

cakephp-3.x - CakePHP3.2 : I can't delete dependent associated

转载 作者:行者123 更新时间:2023-12-02 04:12:57 24 4
gpt4 key购买 nike

我应该犯一个大错误,因为我已经这样做了好几次了,但我真的不明白为什么删除关联仅部分有效:

我的实体是这样声明的:

class SitemessagesTable extends Table {

public function initialize(array $config) {
$this->table('sitemessages');
$this->displayField('title');
$this->addBehavior('Timestamp');

$this->hasMany('SitemessageTitles', [
'dependent' => true,
]);

}
}

class SitemessageTitlesTable extends Table {

public function initialize(array $config) {
$this->table('sitemessage_titles');
$this->displayField('title');

$this->belongsTo('Sitemessages');

$this->hasOne('SitemessageTexts', [
'dependent' => true,
]);

$this->hasOne('SitemessageImages', [
'dependent' => true,
]);

}
}

class SitemessageTextsTable extends Table {

public function initialize(array $config) {
$this->table('sitemessage_texts');
$this->displayField('text');

$this->belongsTo('SitemessageTitles');

}
}

class SitemessageImagesTable extends Table {

public function initialize(array $config) {
$this->table('sitemessage_images');
$this->displayField('image');

$this->belongsTo('SitemessageTitles');

}
}

所以我尝试删除这样的 Sitemessages 实体:

    $sitemessage = $this->Sitemessages->get($sitemessage_id);

$this->Sitemessages->delete($sitemessage);

然后,Sitemessages 和第一级 SitemessageTitles 实体将被删除,但第二级 SitemessageTextsSitemessageImages 实体不会被删除。

我不明白医生所说的:

When deleting entities, associated data can also be deleted. If your HasOne and HasMany associations are configured as dependent, delete operations will ‘cascade’ to those entities as well.

有什么想法吗?

问候,

最佳答案

看来the docsdependent 选项有点不清楚,因为它只会影响第一级关联。如果您想要完全级联删除,还需要启用 cascadeCallbacks 选项。

关于cakephp-3.x - CakePHP3.2 : I can't delete dependent associated,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35508640/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com