Properties

$parent

$parent

$model

$model : \think\Model

Type

Model — 当前关联的模型类

$query

$query : \think\db\Query

Type

Query — 关联模型查询对象

$foreignKey

$foreignKey

$localKey

$localKey

$baseQuery

$baseQuery

$selfRelation

$selfRelation

$morphKey

$morphKey

$morphType

$morphType

$alias

$alias

$relation

$relation

Methods

getParent()

getParent() : \think\Model

获取关联的所属模型

Returns

\think\Model —

getModel()

getModel() : \think\Model

获取当前的关联模型类的实例

Returns

\think\Model —

getQuery()

getQuery() : \think\db\Query

获取关联的查询对象

Returns

\think\db\Query —

selfRelation()

selfRelation(bool  $self = true) : $this

设置当前关联为自关联

Parameters

bool $self

是否自关联

Returns

$this —

isSelfRelation()

isSelfRelation() : bool

当前关联是否为自关联

Returns

bool —

__call()

__call(mixed  $method, mixed  $args) : mixed

Parameters

mixed $method
mixed $args

Returns

mixed —

__construct()

__construct(\think\Model  $parent, string  $morphType, string  $morphKey, array  $alias = [], string  $relation = null) : mixed

构造函数

Parameters

\think\Model $parent

上级模型对象

string $morphType

多态字段名

string $morphKey

外键名

array $alias

多态别名定义

string $relation

关联名

Returns

mixed —

getRelation()

getRelation(string  $subRelation = '', \Closure  $closure = null) : mixed

延迟获取关联数据

Parameters

string $subRelation

子关联名

\Closure $closure

闭包查询条件

Returns

mixed —

has()

has(string  $operator = '>=', int  $count = 1, string  $id = '*', string  $joinType = 'INNER') : \think\model\relation\Query

根据关联条件查询当前模型

Parameters

string $operator

比较操作符

int $count

个数

string $id

关联表的统计字段

string $joinType

JOIN类型

Returns

\think\model\relation\Query —

hasWhere()

hasWhere(mixed  $where = [], mixed  $fields = null) : \think\model\relation\Query

根据关联条件查询当前模型

Parameters

mixed $where

查询条件(数组或者闭包)

mixed $fields

字段

Returns

\think\model\relation\Query —

setAlias()

setAlias(array  $alias) : $this

设置多态别名

Parameters

array $alias

别名定义

Returns

$this —

removeOption()

removeOption() : $this

移除关联查询参数

Returns

$this —

eagerlyResultSet()

eagerlyResultSet(array  $resultSet, string  $relation, string  $subRelation, \Closure  $closure) : void

预载入关联查询

Parameters

array $resultSet

数据集

string $relation

当前关联名

string $subRelation

子关联名

\Closure $closure

闭包

Throws

\think\Exception

eagerlyResult()

eagerlyResult(\think\Model  $result, string  $relation, string  $subRelation, \Closure  $closure) : void

预载入关联查询

Parameters

\think\Model $result

数据对象

string $relation

当前关联名

string $subRelation

子关联名

\Closure $closure

闭包

relationCount()

relationCount(\think\Model  $result, \Closure  $closure) : int

关联统计

Parameters

\think\Model $result

数据对象

\Closure $closure

闭包

Returns

int —

associate()

associate(\think\Model  $model, string  $type = '') : \think\Model

添加关联数据

Parameters

\think\Model $model

关联模型对象

string $type

多态类型

Returns

\think\Model —

dissociate()

dissociate() : \think\Model

注销关联数据

Returns

\think\Model —

getRelationCountQuery()

getRelationCountQuery(\Closure  $closure, string  $name = null) : string

创建关联统计子查询

Parameters

\Closure $closure

闭包

string $name

统计数据别名

Returns

string —

resultSetBuild()

resultSetBuild(array  $resultSet) : mixed

封装关联数据集

Parameters

array $resultSet

数据集

Returns

mixed —

getQueryFields()

getQueryFields(mixed  $model) : mixed

Parameters

mixed $model

Returns

mixed —

getRelationQueryFields()

getRelationQueryFields(mixed  $fields, mixed  $model) : mixed

Parameters

mixed $fields
mixed $model

Returns

mixed —

baseQuery()

baseQuery() : void

执行基础查询(仅执行一次)

parseModel()

parseModel(string  $model) : string

解析模型的完整命名空间

Parameters

string $model

模型名(或者完整类名)

Returns

string —

eagerlyMorphToOne()

eagerlyMorphToOne(object  $model, string  $relation,  $result, string  $subRelation = '') : void

多态MorphTo 关联模型预查询

Parameters

object $model

关联模型对象

string $relation

关联名

$result
string $subRelation

子关联