public function getCounterCache($model)
{
$belongsTo = $this->findBelongsTo($model, ['belongsTo' => []]);
$counterCache = [];
foreach ($belongsTo['belongsTo'] as $otherTable) {
$otherAlias = $otherTable['alias'];
$otherModel = $this->getTableObject($this->_camelize($otherAlias), Inflector::underscore($otherAlias));
try {
$otherSchema = $otherModel->schema();
} catch (\Cake\Database\Exception $e) {
continue;
}
$otherFields = $otherSchema->columns();
$alias = $model->alias();
$field = Inflector::singularize(Inflector::underscore($alias)) . '_count';
if (in_array($field, $otherFields, true)) {
$counterCache[] = "'{$otherAlias}' => ['{$field}']";
}
}
return $counterCache;
}