0

私は次のモデル構造を持っています。

役職

ID、タイトル、テキストなど

鬼ごっこ

ID、名前、posts_count、作成済み

タグ_投稿

id、tag_id、post_id、作成済み

タグ モデル:

public $hasAndBelongsToMany = array(
        'Post' =>
        array(
                'className' => 'Post,
                'joinTable' => 'tags_posts',
                'foreignKey' => 'tag_id',
                'associationForeignKey' => 'post_id',
                'unique' => true,
                'conditions' => '',
                'fields' => '',
                'order' => '',
                'limit' => '',
                'offset' => '',
                'finderQuery' => ''
        )
);

ポストモデル:

public $hasAndBelongsToMany = array(
        'Tag' =>
        array(
                'className' => 'Tag',
                'joinTable' => 'tags_posts',
                'foreignKey' => 'post_id',
                'associationForeignKey' => 'tag_id',
                'unique' => true,
                'conditions' => '',
                'fields' => '',
                'order' => '',
                'limit' => '',
                'offset' => '',
                'finderQuery' => ''
        )
);

タグ投稿モデル:

public $belongsTo = array(
    'Tag' => array(
        'className' => 'Tag',
        'foreignKey' => 'tag_id',
        'conditions' => '',
        'fields' => '',
        'order' => '',
        'counterCache' => 'posts_count'

    ),
    'Post' => array(
        'className' => 'Post',
        'foreignKey' => 'post_id',
        'conditions' => '',
        'fields' => '',
        'order' => ''
    )
);

TagsPost モデルの belongsTo の counterCache が機能しないのはなぜですか? 関連タグ付きの投稿が投稿された場​​合はタグモデルの posts_count を増やし、投稿が削除された場合は減らしたいです。

4

1 に答える 1