protected function _injectResults($objects, $results, $associations, $source)
    {
        $injected = [];
        $properties = $this->_getPropertyMap($source, $associations);
        $primaryKey = (array)$source->getPrimaryKey();
        $results = $results
            ->indexBy(function ($e) use ($primaryKey) {
                /** @var \Cake\Datasource\EntityInterface $e */
                return implode(';', $e->extract($primaryKey));
            })
            ->toArray();

        foreach ($objects as $k => $object) {
            $key = implode(';', $object->extract($primaryKey));
            if (!isset($results[$key])) {
                $injected[$k] = $object;
                continue;
            }

            /** @var \Cake\Datasource\EntityInterface $loaded */
            $loaded = $results[$key];
            foreach ($associations as $assoc) {
                $property = $properties[$assoc];
                $object->set($property, $loaded->get($property), ['useSetters' => false]);
                $object->setDirty($property, false);
            }
            $injected[$k] = $object;
        }

        return $injected;
    }
protected function _injectResults($objects, $results, $associations, $source)
    {
        $injected = [];
        $properties = $this->_getPropertyMap($source, $associations);
        $primaryKey = (array)$source->getPrimaryKey();
        $results = $results
            ->indexBy(function ($e) use ($primaryKey) {
                /** @var \Cake\Datasource\EntityInterface $e */
                return implode(';', $e->extract($primaryKey));
            })
            ->toArray();

        foreach ($objects as $k => $object) {
            $key = implode(';', $object->extract($primaryKey));
            if (!isset($results[$key])) {
                $injected[$k] = $object;
                continue;
            }

            /** @var \Cake\Datasource\EntityInterface $loaded */
            $loaded = $results[$key];
            foreach ($associations as $assoc) {
                $property = $properties[$assoc];
                $object->set($property, $loaded->get($property), ['useSetters' => false]);
                $object->setDirty($property, false);
            }
            $injected[$k] = $object;
        }

        return $injected;
    }
protected function _injectResults ( $ objects , $ results , $ associations , $ source ) { $ injected = [ ] ; $ properties = $ this -> _getPropertyMap ( $ source , $ associations ) ; $ primaryKey = ( array ) $ source -> getPrimaryKey ( ) ; $ results = $ results -> indexBy ( function ( $ e ) use ( $ primaryKey ) { /** @var \Cake\Datasource\EntityInterface $e */ return implode ( ';' , $ e -> extract ( $ primaryKey ) ) ; } ) -> toArray ( ) ; foreach ( $ objects as $ k => $ object ) { $ key = implode ( ';' , $ object -> extract ( $ primaryKey ) ) ; if ( ! isset ( $ results [ $ key ] ) ) { $ injected [ $ k ] = $ object ; continue ; } /** @var \Cake\Datasource\EntityInterface $loaded */ $ loaded = $ results [ $ key ] ; foreach ( $ associations as $ assoc ) { $ property = $ properties [ $ assoc ] ; $ object -> set ( $ property , $ loaded -> get ( $ property ) , [ 'useSetters' => false ] ) ; $ object -> setDirty ( $ property , false ) ; } $ injected [ $ k ] = $ object ; } return $ injected ; }
Injects the results of the eager loader query into the original list of
entities.

@param \Cake\Datasource\EntityInterface[]|\Traversable $objects The original list of entities
@param \Cake\Collection\CollectionInterface|\Cake\Database\Query $results The loaded results
@param string[] $associations The top level associations that were loaded
@param \Cake\ORM\Table $source The table where the entities came from
@return array
Injects the results of the eager loader query into the original list of entities .