public function attachCounters()
    {
        $config = $this->getConfig();
        $tagsAlias = $config['tagsAlias'];
        $taggedAlias = $config['taggedAlias'];

        $taggedTable = $this->_table->{$taggedAlias};

        if (!$taggedTable->hasBehavior('CounterCache')) {
            $taggedTable->addBehavior('CounterCache');
        }

        $counterCache = $taggedTable->behaviors()->CounterCache;

        if (!$counterCache->getConfig($tagsAlias)) {
            $counterCache->setConfig($tagsAlias, $config['tagsCounter']);
        }

        if ($config['taggedCounter'] === false) {
            return;
        }

        foreach ($config['taggedCounter'] as $field => $o) {
            if (!$this->_table->hasField($field)) {
                throw new RuntimeException(sprintf(
                    'Field "%s" does not exist in table "%s"',
                    $field,
                    $this->_table->getTable()
                ));
            }
        }

        if (!$counterCache->getConfig($taggedAlias)) {
            $field = key($config['taggedCounter']);
            $config['taggedCounter']['tag_count']['conditions'] = [
                $taggedTable->aliasField($this->getConfig('fkTableField')) => $this->_table->getTable(),
            ];
            $counterCache->setConfig($this->_table->getAlias(), $config['taggedCounter']);
        }
    }