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

belongsToMany() публичный Метод

BELONGS TO MANY 关联定义
public belongsToMany ( string $model, string $table, string $foreignKey, string $localKey, array $alias )
$model string 模型名
$table string 中间表名
$foreignKey string 关联模型外键
$localKey string 当前模型关联键
$alias array 别名定义
    public function belongsToMany($model, $table, $foreignKey, $localKey, $alias)
    {
        // 记录当前关联信息
        $this->type = self::BELONGS_TO_MANY;
        $this->model = $model;
        $this->foreignKey = $foreignKey;
        $this->localKey = $localKey;
        $this->middle = $table;
        $this->alias = $alias;
        $this->query = (new $model())->db();
        // 返回关联的模型对象
        return $this;
    }