protected function _processAssociation(Event $event, EntityInterface $entity, Association $assoc, array $settings)
    {
        $foreignKeys = (array)$assoc->getForeignKey();
        $primaryKeys = (array)$assoc->getBindingKey();
        $countConditions = $entity->extract($foreignKeys);
        $updateConditions = array_combine($primaryKeys, $countConditions);
        $countOriginalConditions = $entity->extractOriginalChanged($foreignKeys);

        if ($countOriginalConditions !== []) {
            $updateOriginalConditions = array_combine($primaryKeys, $countOriginalConditions);
        }

        foreach ($settings as $field => $config) {
            if (is_int($field)) {
                $field = $config;
                $config = [];
            }

            if (isset($this->_ignoreDirty[$assoc->getTarget()->getRegistryAlias()][$field]) &&
                $this->_ignoreDirty[$assoc->getTarget()->getRegistryAlias()][$field] === true
            ) {
                continue;
            }

            if (is_callable($config)) {
                if (is_string($config)) {
                    throw new RuntimeException('You must not use a string as callable.');
                }
                $count = $config($event, $entity, $this->_table, false);
            } else {
                $count = $this->_getCount($config, $countConditions);
            }
            if ($count !== false) {
                $assoc->getTarget()->updateAll([$field => $count], $updateConditions);
            }

            if (isset($updateOriginalConditions)) {
                if (is_callable($config)) {
                    if (is_string($config)) {
                        throw new RuntimeException('You must not use a string as callable.');
                    }
                    $count = $config($event, $entity, $this->_table, true);
                } else {
                    $count = $this->_getCount($config, $countOriginalConditions);
                }
                if ($count !== false) {
                    $assoc->getTarget()->updateAll([$field => $count], $updateOriginalConditions);
                }
            }
        }
    }
protected function _processAssociation(Event $event, EntityInterface $entity, Association $assoc, array $settings)
    {
        $foreignKeys = (array)$assoc->getForeignKey();
        $primaryKeys = (array)$assoc->getBindingKey();
        $countConditions = $entity->extract($foreignKeys);
        $updateConditions = array_combine($primaryKeys, $countConditions);
        $countOriginalConditions = $entity->extractOriginalChanged($foreignKeys);

        if ($countOriginalConditions !== []) {
            $updateOriginalConditions = array_combine($primaryKeys, $countOriginalConditions);
        }

        foreach ($settings as $field => $config) {
            if (is_int($field)) {
                $field = $config;
                $config = [];
            }

            if (isset($this->_ignoreDirty[$assoc->getTarget()->getRegistryAlias()][$field]) &&
                $this->_ignoreDirty[$assoc->getTarget()->getRegistryAlias()][$field] === true
            ) {
                continue;
            }

            if (is_callable($config)) {
                if (is_string($config)) {
                    throw new RuntimeException('You must not use a string as callable.');
                }
                $count = $config($event, $entity, $this->_table, false);
            } else {
                $count = $this->_getCount($config, $countConditions);
            }
            if ($count !== false) {
                $assoc->getTarget()->updateAll([$field => $count], $updateConditions);
            }

            if (isset($updateOriginalConditions)) {
                if (is_callable($config)) {
                    if (is_string($config)) {
                        throw new RuntimeException('You must not use a string as callable.');
                    }
                    $count = $config($event, $entity, $this->_table, true);
                } else {
                    $count = $this->_getCount($config, $countOriginalConditions);
                }
                if ($count !== false) {
                    $assoc->getTarget()->updateAll([$field => $count], $updateOriginalConditions);
                }
            }
        }
    }
protected function _processAssociation ( Event $ event , EntityInterface $ entity , Association $ assoc , array $ settings ) { $ foreignKeys = ( array ) $ assoc -> getForeignKey ( ) ; $ primaryKeys = ( array ) $ assoc -> getBindingKey ( ) ; $ countConditions = $ entity -> extract ( $ foreignKeys ) ; $ updateConditions = array_combine ( $ primaryKeys , $ countConditions ) ; $ countOriginalConditions = $ entity -> extractOriginalChanged ( $ foreignKeys ) ; if ( $ countOriginalConditions !== [ ] ) { $ updateOriginalConditions = array_combine ( $ primaryKeys , $ countOriginalConditions ) ; } foreach ( $ settings as $ field => $ config ) { if ( is_int ( $ field ) ) { $ field = $ config ; $ config = [ ] ; } if ( isset ( $ this -> _ignoreDirty [ $ assoc -> getTarget ( ) -> getRegistryAlias ( ) ] [ $ field ] ) && $ this -> _ignoreDirty [ $ assoc -> getTarget ( ) -> getRegistryAlias ( ) ] [ $ field ] === true ) { continue ; } if ( is_callable ( $ config ) ) { if ( is_string ( $ config ) ) { throw new RuntimeException ( 'You must not use a string as callable.' ) ; } $ count = $ config ( $ event , $ entity , $ this -> _table , false ) ; } else { $ count = $ this -> _getCount ( $ config , $ countConditions ) ; } if ( $ count !== false ) { $ assoc -> getTarget ( ) -> updateAll ( [ $ field => $ count ] , $ updateConditions ) ; } if ( isset ( $ updateOriginalConditions ) ) { if ( is_callable ( $ config ) ) { if ( is_string ( $ config ) ) { throw new RuntimeException ( 'You must not use a string as callable.' ) ; } $ count = $ config ( $ event , $ entity , $ this -> _table , true ) ; } else { $ count = $ this -> _getCount ( $ config , $ countOriginalConditions ) ; } if ( $ count !== false ) { $ assoc -> getTarget ( ) -> updateAll ( [ $ field => $ count ] , $ updateOriginalConditions ) ; } } } }
Updates counter cache for a single association

@param \Cake\Event\Event $event Event instance.
@param \Cake\Datasource\EntityInterface $entity Entity
@param \Cake\ORM\Association $assoc The association object
@param array $settings The settings for for counter cache for this association
@return void
@throws \RuntimeException If invalid callable is passed.
Updates counter cache for a single association