Cakephp 3.0 CakePHP 3计数器缓存在使用belongToMany SelfJoinTable进行删除时未更新

Cakephp 3.0 CakePHP 3计数器缓存在使用belongToMany SelfJoinTable进行删除时未更新,cakephp-3.0,self-join,counter-cache,Cakephp 3.0,Self Join,Counter Cache,CakePHP vertion:3.3.11 计数器缓存正在处理添加方法,但不处理删除方法 句子表 $this->belongsToMany('Sentences', [ 'foreignKey' => 'second_sentence_id', 'targetForeignKey' => 'sentence_id', 'joinTable' => 'sentences_sentences' ]);

CakePHP vertion:3.3.11

计数器缓存正在处理添加方法,但不处理删除方法

句子表

    $this->belongsToMany('Sentences', [
        'foreignKey' => 'second_sentence_id',
        'targetForeignKey' => 'sentence_id',
        'joinTable' => 'sentences_sentences'
    ]);
    $this->belongsToMany('SecondSentences', [
        'className' => 'Sentences',
        'foreignKey' => 'sentence_id',
        'targetForeignKey' => 'second_sentence_id',
        'joinTable' => 'sentences_sentences'
    ]);
句子内容表

    $this->belongsTo('Sentences', [
        'foreignKey' => 'sentence_id',
        'joinType' => 'INNER'
    ]);
    $this->belongsTo('SecondSentences', [
        'className'=>'Sentences',
        'foreignKey' => 'second_sentence_id',
        'joinType' => 'INNER'
    ]);

    $this->addBehavior('CounterCache', ['Sentences' => ['ver_count']]);
语句控制器添加方法更新版本计数

$sentence = $this->Sentences->get($this->request->data['id']);
$sentence = $this->Sentences->patchEntity($sentence, $this->request->data);
            $this->Sentences->SecondSentences->saveStrategy('append');
            $this->Sentences->save($sentence);
$sentence = $this->Sentences->SecondSentences->get($this->request->data['id'],['contain'=>['Sentences']]);
if ($sentence->user_id == $this->Auth->user('id')) {
   $this->Sentences->SecondSentences->delete($sentence);
   $sentences = $this->Sentences->get($sentence->sentences[0]->id,['contain'=>['SecondSentences']]);

// NOW I AM USING BELOW CODE FOR UPDATING VER_COUNT.
   $this->Sentences->updateAll(['ver_count'=>count($sentences->second_sentences)], ['id'=>$sentence->sentences[0]->id]);
}
SentencesController删除方法不更新版本计数

$sentence = $this->Sentences->get($this->request->data['id']);
$sentence = $this->Sentences->patchEntity($sentence, $this->request->data);
            $this->Sentences->SecondSentences->saveStrategy('append');
            $this->Sentences->save($sentence);
$sentence = $this->Sentences->SecondSentences->get($this->request->data['id'],['contain'=>['Sentences']]);
if ($sentence->user_id == $this->Auth->user('id')) {
   $this->Sentences->SecondSentences->delete($sentence);
   $sentences = $this->Sentences->get($sentence->sentences[0]->id,['contain'=>['SecondSentences']]);

// NOW I AM USING BELOW CODE FOR UPDATING VER_COUNT.
   $this->Sentences->updateAll(['ver_count'=>count($sentences->second_sentences)], ['id'=>$sentence->sentences[0]->id]);
}
如何删除您的记录。正如cakephp文档()中提到的:

以及:


先确认一下。

发布你的添加和删除方法,以便有人能帮助你。是的,这是我的错,关联是原因,但在添加方法上与BelgongTomany关联起作用。