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

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

BELONGS TO 关联定义
public belongsTo ( string $model, string $foreignKey, string $otherKey, array $alias = [], string $joinType = 'INNER' )
$model string 模型名
$foreignKey string 关联外键
$otherKey string 关联主键
$alias array 别名定义
$joinType string JOIN类型
    public function belongsTo($model, $foreignKey, $otherKey, $alias = [], $joinType = 'INNER')
    {
        // 记录当前关联信息
        $this->type = self::BELONGS_TO;
        $this->model = $model;
        $this->foreignKey = $foreignKey;
        $this->localKey = $otherKey;
        $this->alias = $alias;
        $this->joinType = $joinType;
        $this->query = (new $model())->db();
        // 返回关联的模型对象
        return $this;
    }