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' // Will be using findPublished()
]
]
]
Counter cache using lambda function returning the count This is equivalent to example #2
[
'Users' => [
'posts_published' => function (Event $event, EntityInterface $entity, Table $table) {
$query = $table->find('all')->where([
'published' => true,
'user_id' => $entity->get('user_id')
]);
return $query->count();
}
]
]
When using a lambda function you can return false to disable updating the counter value
for the current operation.
Ignore updating the field if it is dirty
[
'Users' => [
'posts_published' => [
'ignoreDirty' => true
]
]
]
You can disable counter updates entirely by sending the ignoreCounterCache option
to your save operation:
$this->Articles->save($article, ['ignoreCounterCache' => true]);
Class TimestampBehavior
This behavior provides a way to translate dynamic data by keeping translations in a separate table linked to the original record from another one. Translated fields can be configured to override those in the main table when fetched or put aside into another property for the same entity.
If you wish to override fields, you need to call the locale method in this
behavior for setting the language you want to fetch from the translations table.
If you want to bring all or certain languages for each of the fetched records,
you can use the custom translations finders that is exposed to the table.
Makes the table to which this is attached to behave like a nested set and provides methods for managing and retrieving information out of the derived hierarchical structure.
Tables attaching this behavior are required to have a column referencing the parent row, and two other numeric columns (lft and rght) where the implicit order will be cached.
For more information on what is a nested set and a how it works refer to https://www.sitepoint.com/hierarchical-data-database-2/