think\Model::belongsToMany PHP Method

belongsToMany() public method

BELONGS TO MANY 关联定义
public belongsToMany ( string $model, string $table = '', string $foreignKey = '', string $localKey = '', array $alias = [] ) : Relation
$model string 模型名
$table string 中间表名
$foreignKey string 关联外键
$localKey string 当前模型关联键
$alias array 别名定义
return think\model\Relation
    public function belongsToMany($model, $table = '', $foreignKey = '', $localKey = '', $alias = [])
    {
        // 记录当前关联信息
        $model = $this->parseModel($model);
        $name = Loader::parseName(basename(str_replace('\\', '/', $model)));
        $table = $table ?: $this->db()->getTable(Loader::parseName($this->name) . '_' . $name);
        $foreignKey = $foreignKey ?: $name . '_id';
        $localKey = $localKey ?: Loader::parseName($this->name) . '_id';
        return $this->relation()->belongsToMany($model, $table, $foreignKey, $localKey, $alias);
    }