protected function _processAssociation(Event $event, EntityInterface $entity, Association $assoc, array $settings)
    {
        $foreignKeys = (array)$assoc->foreignKey();
        $primaryKeys = (array)$assoc->bindingKey();
        $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 (!is_string($config) && is_callable($config)) {
                $count = $config($event, $entity, $this->_table, false, $countConditions);
            } else {
                $count = $this->_getCount($config, $countConditions);
            }

            $assoc->target()->updateAll([$field => $count], $updateConditions);

            if (isset($updateOriginalConditions)) {
                if (!is_string($config) && is_callable($config)) {
                    $count = $config($event, $entity, $this->_table, true, $countOriginalConditions);
                } else {
                    $count = $this->_getCount($config, $countOriginalConditions);
                }
                $assoc->target()->updateAll([$field => $count], $updateOriginalConditions);
            }
        }
    }
protected function _processAssociation(Event $event, EntityInterface $entity, Association $assoc, array $settings)
    {
        $foreignKeys = (array)$assoc->foreignKey();
        $primaryKeys = (array)$assoc->bindingKey();
        $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 (!is_string($config) && is_callable($config)) {
                $count = $config($event, $entity, $this->_table, false, $countConditions);
            } else {
                $count = $this->_getCount($config, $countConditions);
            }

            $assoc->target()->updateAll([$field => $count], $updateConditions);

            if (isset($updateOriginalConditions)) {
                if (!is_string($config) && is_callable($config)) {
                    $count = $config($event, $entity, $this->_table, true, $countOriginalConditions);
                } else {
                    $count = $this->_getCount($config, $countOriginalConditions);
                }
                $assoc->target()->updateAll([$field => $count], $updateOriginalConditions);
            }
        }
    }
protected function _processAssociation ( Event $ event , EntityInterface $ entity , Association $ assoc , array $ settings ) { $ foreignKeys = ( array ) $ assoc -> foreignKey ( ) ; $ primaryKeys = ( array ) $ assoc -> bindingKey ( ) ; $ 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 ( ! is_string ( $ config ) && is_callable ( $ config ) ) { $ count = $ config ( $ event , $ entity , $ this -> _table , false , $ countConditions ) ; } else { $ count = $ this -> _getCount ( $ config , $ countConditions ) ; } $ assoc -> target ( ) -> updateAll ( [ $ field => $ count ] , $ updateConditions ) ; if ( isset ( $ updateOriginalConditions ) ) { if ( ! is_string ( $ config ) && is_callable ( $ config ) ) { $ count = $ config ( $ event , $ entity , $ this -> _table , true , $ countOriginalConditions ) ; } else { $ count = $ this -> _getCount ( $ config , $ countOriginalConditions ) ; } $ assoc -> target ( ) -> updateAll ( [ $ field => $ count ] , $ updateOriginalConditions ) ; } } }
Updates sum cache for a single association

@param \Cake\Event\Event $event Event instance.
@param \Cake\Datasource\EntityInterface $entity Entity
@param Association $assoc The association object
@param array $settings The settings for sum cache for this association
@return void
Updates sum cache for a single association