think\model\Relation::eagerlyManyToMany PHP Метод

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

多对多 关联模型预查询
protected eagerlyManyToMany ( object $model, array $where, string $relation, string $subRelation = '' ) : array
$model object 关联模型对象
$where array 关联预查询条件
$relation string 关联名
$subRelation string 子关联
Результат array
    protected function eagerlyManyToMany($model, $where, $relation, $subRelation = '')
    {
        $foreignKey = $this->foreignKey;
        $localKey = $this->localKey;
        // 预载入关联查询 支持嵌套预载入
        $list = $this->belongsToManyQuery($model, $this->middle, $foreignKey, $localKey, $where)->with($subRelation)->select();
        // 组装模型数据
        $data = [];
        foreach ($list as $set) {
            $pivot = [];
            foreach ($set->getData() as $key => $val) {
                if (strpos($key, '__')) {
                    list($name, $attr) = explode('__', $key, 2);
                    if ('pivot' == $name) {
                        $pivot[$attr] = $val;
                        unset($set->{$key});
                    }
                }
            }
            $set->pivot = new Pivot($pivot, $this->middle);
            $data[$pivot[$localKey]][] = $set;
        }
        return $data;
    }