protected function _collectKeys($external, $query, $statement)
    {
        $collectKeys = [];
        /* @var \Cake\ORM\EagerLoadable $meta */
        foreach ($external as $meta) {
            $instance = $meta->instance();
            if (!$instance->requiresKeys($meta->getConfig())) {
                continue;
            }

            $source = $instance->getSource();
            $keys = $instance->type() === Association::MANY_TO_ONE ?
                (array)$instance->getForeignKey() :
                (array)$instance->getBindingKey();

            $alias = $source->getAlias();
            $pkFields = [];
            foreach ($keys as $key) {
                $pkFields[] = key($query->aliasField($key, $alias));
            }
            $collectKeys[$meta->aliasPath()] = [$alias, $pkFields, count($pkFields) === 1];
        }

        if (empty($collectKeys)) {
            return [[], $statement];
        }

        if (!($statement instanceof BufferedStatement)) {
            $statement = new BufferedStatement($statement, $query->getConnection()->getDriver());
        }

        return [$this->_groupKeys($statement, $collectKeys), $statement];
    }
protected function _collectKeys($external, $query, $statement)
    {
        $collectKeys = [];
        /* @var \Cake\ORM\EagerLoadable $meta */
        foreach ($external as $meta) {
            $instance = $meta->instance();
            if (!$instance->requiresKeys($meta->getConfig())) {
                continue;
            }

            $source = $instance->getSource();
            $keys = $instance->type() === Association::MANY_TO_ONE ?
                (array)$instance->getForeignKey() :
                (array)$instance->getBindingKey();

            $alias = $source->getAlias();
            $pkFields = [];
            foreach ($keys as $key) {
                $pkFields[] = key($query->aliasField($key, $alias));
            }
            $collectKeys[$meta->aliasPath()] = [$alias, $pkFields, count($pkFields) === 1];
        }

        if (empty($collectKeys)) {
            return [[], $statement];
        }

        if (!($statement instanceof BufferedStatement)) {
            $statement = new BufferedStatement($statement, $query->getConnection()->getDriver());
        }

        return [$this->_groupKeys($statement, $collectKeys), $statement];
    }
protected function _collectKeys ( $ external , $ query , $ statement ) { $ collectKeys = [ ] ; /* @var \Cake\ORM\EagerLoadable $meta */ foreach ( $ external as $ meta ) { $ instance = $ meta -> instance ( ) ; if ( ! $ instance -> requiresKeys ( $ meta -> getConfig ( ) ) ) { continue ; } $ source = $ instance -> getSource ( ) ; $ keys = $ instance -> type ( ) === Association :: MANY_TO_ONE ? ( array ) $ instance -> getForeignKey ( ) : ( array ) $ instance -> getBindingKey ( ) ; $ alias = $ source -> getAlias ( ) ; $ pkFields = [ ] ; foreach ( $ keys as $ key ) { $ pkFields [ ] = key ( $ query -> aliasField ( $ key , $ alias ) ) ; } $ collectKeys [ $ meta -> aliasPath ( ) ] = [ $ alias , $ pkFields , count ( $ pkFields ) === 1 ] ; } if ( empty ( $ collectKeys ) ) { return [ [ ] , $ statement ] ; } if ( ! ( $ statement instanceof BufferedStatement ) ) { $ statement = new BufferedStatement ( $ statement , $ query -> getConnection ( ) -> getDriver ( ) ) ; } return [ $ this -> _groupKeys ( $ statement , $ collectKeys ) , $ statement ] ; }
Helper function used to return the keys from the query records that will be used
to eagerly load associations.

@param array $external the list of external associations to be loaded
@param \Cake\ORM\Query $query The query from which the results where generated
@param \Cake\Database\Statement\BufferedStatement $statement The statement to work on
@return array
Helper function used to return the keys from the query records that will be used to eagerly load associations .