public function loadExternal($query, $statement)
    {
        $external = $this->externalAssociations($query->getRepository());
        if (empty($external)) {
            return $statement;
        }

        $driver = $query->getConnection()->getDriver();
        list($collected, $statement) = $this->_collectKeys($external, $query, $statement);

        foreach ($external as $meta) {
            $contain = $meta->associations();
            $instance = $meta->instance();
            $config = $meta->getConfig();
            $alias = $instance->getSource()->getAlias();
            $path = $meta->aliasPath();

            $requiresKeys = $instance->requiresKeys($config);
            if ($requiresKeys && empty($collected[$path][$alias])) {
                continue;
            }

            $keys = isset($collected[$path][$alias]) ? $collected[$path][$alias] : null;
            $f = $instance->eagerLoader(
                $config + [
                    'query' => $query,
                    'contain' => $contain,
                    'keys' => $keys,
                    'nestKey' => $meta->aliasPath()
                ]
            );
            $statement = new CallbackStatement($statement, $driver, $f);
        }

        return $statement;
    }
public function loadExternal($query, $statement)
    {
        $external = $this->externalAssociations($query->getRepository());
        if (empty($external)) {
            return $statement;
        }

        $driver = $query->getConnection()->getDriver();
        list($collected, $statement) = $this->_collectKeys($external, $query, $statement);

        foreach ($external as $meta) {
            $contain = $meta->associations();
            $instance = $meta->instance();
            $config = $meta->getConfig();
            $alias = $instance->getSource()->getAlias();
            $path = $meta->aliasPath();

            $requiresKeys = $instance->requiresKeys($config);
            if ($requiresKeys && empty($collected[$path][$alias])) {
                continue;
            }

            $keys = isset($collected[$path][$alias]) ? $collected[$path][$alias] : null;
            $f = $instance->eagerLoader(
                $config + [
                    'query' => $query,
                    'contain' => $contain,
                    'keys' => $keys,
                    'nestKey' => $meta->aliasPath()
                ]
            );
            $statement = new CallbackStatement($statement, $driver, $f);
        }

        return $statement;
    }
public function loadExternal ( $ query , $ statement ) { $ external = $ this -> externalAssociations ( $ query -> getRepository ( ) ) ; if ( empty ( $ external ) ) { return $ statement ; } $ driver = $ query -> getConnection ( ) -> getDriver ( ) ; list ( $ collected , $ statement ) = $ this -> _collectKeys ( $ external , $ query , $ statement ) ; foreach ( $ external as $ meta ) { $ contain = $ meta -> associations ( ) ; $ instance = $ meta -> instance ( ) ; $ config = $ meta -> getConfig ( ) ; $ alias = $ instance -> getSource ( ) -> getAlias ( ) ; $ path = $ meta -> aliasPath ( ) ; $ requiresKeys = $ instance -> requiresKeys ( $ config ) ; if ( $ requiresKeys && empty ( $ collected [ $ path ] [ $ alias ] ) ) { continue ; } $ keys = isset ( $ collected [ $ path ] [ $ alias ] ) ? $ collected [ $ path ] [ $ alias ] : null ; $ f = $ instance -> eagerLoader ( $ config + [ 'query' => $ query , 'contain' => $ contain , 'keys' => $ keys , 'nestKey' => $ meta -> aliasPath ( ) ] ) ; $ statement = new CallbackStatement ( $ statement , $ driver , $ f ) ; } return $ statement ; }
Decorates the passed statement object in order to inject data from associations
that cannot be joined directly.

@param \Cake\ORM\Query $query The query for which to eager load external
associations
@param \Cake\Database\StatementInterface $statement The statement created after executing the $query
@return \Cake\Database\StatementInterface statement modified statement with extra loaders
Decorates the passed statement object in order to inject data from associations that cannot be joined directly .