Cake\ORM\Association\BelongsToMany::_buildQuery PHP Метод

_buildQuery() защищенный Метод

This is used for eager loading records on the target table based on conditions.
protected _buildQuery ( array $options ) : Query
$options array options accepted by eagerLoader()
Результат Cake\ORM\Query
    protected function _buildQuery($options)
    {
        $name = $this->_junctionAssociationName();
        $assoc = $this->target()->association($name);
        $queryBuilder = false;
        if (!empty($options['queryBuilder'])) {
            $queryBuilder = $options['queryBuilder'];
            unset($options['queryBuilder']);
        }
        $query = $this->_buildBaseQuery($options);
        $query->addDefaultTypes($assoc->target());
        if ($queryBuilder) {
            $query = $queryBuilder($query);
        }
        $query = $this->_appendJunctionJoin($query, []);
        if ($query->autoFields() === null) {
            $query->autoFields($query->clause('select') === []);
        }
        // Ensure that association conditions are applied
        // and that the required keys are in the selected columns.
        $tempName = $this->_name . '_CJoin';
        $schema = $assoc->schema();
        $joinFields = $types = [];
        foreach ($schema->typeMap() as $f => $type) {
            $key = $tempName . '__' . $f;
            $joinFields[$key] = "{$name}.{$f}";
            $types[$key] = $type;
        }
        $query->where($this->junctionConditions())->select($joinFields)->defaultTypes($types)->addDefaultTypes($this->target());
        $query->eagerLoader()->addToJoinsMap($tempName, $assoc, false, $this->_junctionProperty);
        $assoc->attachTo($query, ['aliasPath' => $assoc->alias(), 'includeFields' => false, 'propertyPath' => $this->_junctionProperty]);
        return $query;
    }