Properties

$parent

$parent : \think\Model

父模型对象

Type

\think\Model

$model

$model : string

当前关联的模型类名

Type

string

$query

$query : \think\db\BaseQuery

关联模型查询对象

Type

\think\db\BaseQuery

$foreignKey

$foreignKey : string

关联表外键

Type

string

$localKey

$localKey : string

关联表主键

Type

string

$baseQuery

$baseQuery : boolean

是否执行关联基础查询

Type

boolean

$selfRelation

$selfRelation : boolean

是否为自关联

Type

boolean

$withLimit

$withLimit : integer

关联数据数量限制

Type

integer

$withField

$withField : array

关联数据字段限制

Type

array

$morphKey

$morphKey : string

多态关联外键

Type

string

$morphType

$morphType : string

多态字段

Type

string

$alias

$alias : array

多态别名

Type

array

$relation

$relation : string

关联名

Type

string

Methods

getParent()

getParent() : \think\Model

获取关联的所属模型

Returns

\think\Model

getQuery()

getQuery() : \think\db\BaseQuery

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

Returns

\think\db\BaseQuery

getModel()

getModel() : \think\Model

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

Returns

\think\Model

isSelfRelation()

isSelfRelation() : boolean

当前关联是否为自关联

Returns

boolean

update()

update(array  $data = array()) : integer

更新数据

Parameters

array $data

更新数据

Returns

integer

delete()

delete(mixed  $data = null) : integer

删除记录

Parameters

mixed $data

表达式 true 表示强制删除

Throws

\think\db\exception\DbException
\think\model\PDOException

Returns

integer

withLimit()

withLimit(integer  $limit) : $this

限制关联数据的数量

Parameters

integer $limit

关联数量限制

Returns

$this

withField()

withField(array  $field) : $this

限制关联数据的字段

Parameters

array $field

关联字段限制

Returns

$this

__call()

__call(  $method,   $args) 

Parameters

$method
$args

__construct()

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

架构函数

Parameters

\think\Model $parent

上级模型对象

string $morphType

多态字段名

string $morphKey

外键名

array $alias

多态别名定义

string $relation

关联名

getRelation()

getRelation(array  $subRelation = array(), \Closure  $closure = null) : \think\Model

延迟获取关联数据

Parameters

array $subRelation

子关联名

\Closure $closure

闭包查询条件

Returns

\think\Model

has()

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

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

Parameters

string $operator

比较操作符

integer $count

个数

string $id

关联表的统计字段

string $joinType

JOIN类型

\think\model\relation\Query $query

Query对象

Returns

\think\model\relation\Query

hasWhere()

hasWhere(mixed  $where = array(), mixed  $fields = null, string  $joinType = '', \think\model\relation\Query  $query = null) : \think\model\relation\Query

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

Parameters

mixed $where

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

mixed $fields

字段

string $joinType

JOIN类型

\think\model\relation\Query $query

Query对象

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, array  $subRelation, \Closure  $closure = null, array  $cache = array()) : void

预载入关联查询

Parameters

array $resultSet

数据集

string $relation

当前关联名

array $subRelation

子关联名

\Closure $closure

闭包

array $cache

关联缓存

Throws

\think\db\exception\DbException

eagerlyResult()

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

预载入关联查询

Parameters

\think\Model $result

数据对象

string $relation

当前关联名

array $subRelation

子关联名

\Closure $closure

闭包

array $cache

关联缓存

relationCount()

relationCount(\think\Model  $result, \Closure  $closure = null, string  $aggregate = 'count', string  $field = '*') : integer

关联统计

Parameters

\think\Model $result

数据对象

\Closure $closure

闭包

string $aggregate

聚合查询方法

string $field

字段

Returns

integer

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

resultSetBuild()

resultSetBuild(array  $resultSet, \think\Model  $parent = null) : mixed

封装关联数据集

Parameters

array $resultSet

数据集

\think\Model $parent

父模型

Returns

mixed

getQueryFields()

getQueryFields(\think\model\string  $model) 

Parameters

\think\model\string $model

getRelationQueryFields()

getRelationQueryFields(  $fields, \think\model\string  $model) 

Parameters

$fields
\think\model\string $model

getQueryWhere()

getQueryWhere(array  $where, \think\model\string  $relation) 

Parameters

array $where
\think\model\string $relation

getClosureType()

getClosureType(\Closure  $closure) : mixed

判断闭包的参数类型

Parameters

\Closure $closure

Returns

mixed

baseQuery()

baseQuery() : void

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

parseModel()

parseModel(string  $model) : string

解析模型的完整命名空间

Parameters

string $model

模型名(或者完整类名)

Returns

string

eagerlyMorphToOne()

eagerlyMorphToOne(string  $model, string  $relation, \think\Model  $result, array  $subRelation = array(), array  $cache = array()) : void

多态MorphTo 关联模型预查询

Parameters

string $model

关联模型对象

string $relation

关联名

\think\Model $result
array $subRelation

子关联

array $cache

关联缓存