Cake\ORM\Association\BelongsToMany::_buildResultMap PHP Method

_buildResultMap() protected method

Builds an array containing the results from fetchQuery indexed by the foreignKey value corresponding to this association.
protected _buildResultMap ( Query $fetchQuery, array $options ) : array
$fetchQuery Cake\ORM\Query The query to get results from
$options array The options passed to the eager loader
return array
    protected function _buildResultMap($fetchQuery, $options)
    {
        $resultMap = [];
        $key = (array) $options['foreignKey'];
        $hydrated = $fetchQuery->hydrate();
        foreach ($fetchQuery->all() as $result) {
            if (!isset($result[$this->_junctionProperty])) {
                throw new RuntimeException(sprintf('"%s" is missing from the belongsToMany results. Results cannot be created.', $this->_junctionProperty));
            }
            $values = [];
            foreach ($key as $k) {
                $values[] = $result[$this->_junctionProperty][$k];
            }
            $resultMap[implode(';', $values)][] = $result;
        }
        return $resultMap;
    }