CounterCacheBehavior (class)

Class CounterCacheBehavior

CounterCache behavior

Enables models to cache the amount of connections in a given relation.

Examples with Post model belonging to User model

Regular counter cache

[
    'Users' => [
        'post_count'
    ]
]

Counter cache with scope

[
    'Users' => [
        'posts_published' => [
            'conditions' => [
                'published' => true
            ]
        ]
    ]
]

Counter cache using custom find

[
    'Users' => [
        'posts_published' => [
            'finder' => 'published' 登录查看完整内容