PHP Класс think\model\Relation

Показать файл Открыть проект

Защищенные свойства (Protected)

Свойство Тип Описание
$alias 数据表别名
$foreignKey 关联表外键
$joinType 当前关联的JOIN类型
$localKey 关联表主键
$middle 中间表模型
$model 当前关联的模型类
$parent 父模型对象
$query 关联模型查询对象
$throughKey 中间关联表外键
$type 当前关联类型
$where 关联查询条件

Открытые методы

Метод Описание
__call ( $method, $args )
__construct ( Model $model ) 架构函数
attach ( mixed $data, array $pivot = [] ) : integer 附加关联的一个中间表数据
belongsTo ( string $model, string $foreignKey, string $otherKey, array $alias = [], string $joinType = 'INNER' ) BELONGS TO 关联定义
belongsToMany ( string $model, string $table, string $foreignKey, string $localKey, array $alias ) BELONGS TO MANY 关联定义
detach ( integer | array $data, boolean $relationDel = false ) : integer 解除关联的一个中间表数据
eagerlyResult ( Model $result, string $relation, string $class = '' ) : Model 预载入关联查询 返回模型对象
eagerlyResultSet ( array $resultSet, string $relation, string $class = '' ) : array 预载入关联查询 返回数据集
getRelation ( $name ) 获取关联数据
getRelationInfo ( string $name = '' ) : array | string | integer 获取当前关联信息
hasMany ( string $model, string $foreignKey, string $localKey, array $alias ) HAS MANY 关联定义
hasManyThrough ( string $model, string $through, $foreignKey, $throughKey, string $localKey, array $alias ) HAS MANY 远程关联定义
hasOne ( string $model, string $foreignKey, string $localKey, array $alias = [], string $joinType = 'INNER' ) HAS ONE 关联定义
save ( mixed $data, array $pivot = [] ) : integer 保存(新增)当前关联数据对象
saveAll ( array $dataSet, array $pivot = [] ) : integer 批量保存当前关联数据对象
setAlias ( array $alias ) 设置当前关联定义的数据表别名

Защищенные методы

Метод Описание
belongsToManyQuery ( object $model, string $table, string $foreignKey, string $localKey, array $condition = [] ) : Query | string BELONGS TO MANY 关联查询
eagerlyManyToMany ( object $model, array $where, string $relation, string $subRelation = '' ) : array 多对多 关联模型预查询
eagerlyOneToMany ( object $model, array $where, string $relation, string $subRelation = '', boolean $closure = false ) : array 一对多 关联模型预查询
match ( string $model, string $relation, Model &$result ) : void 一对一 关联模型预查询拼装
resultSetBuild ( array $resultSet, string $class = '' ) : mixed 封装关联数据集

Описание методов

__call() публичный метод

public __call ( $method, $args )

__construct() публичный метод

架构函数
public __construct ( Model $model )
$model think\Model 上级模型对象

attach() публичный метод

附加关联的一个中间表数据
public attach ( mixed $data, array $pivot = [] ) : integer
$data mixed 数据 可以使用数组、关联模型对象 或者 关联对象的主键
$pivot array 中间表额外数据
Результат integer

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类型

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 别名定义

belongsToManyQuery() защищенный метод

BELONGS TO MANY 关联查询
protected belongsToManyQuery ( object $model, string $table, string $foreignKey, string $localKey, array $condition = [] ) : Query | string
$model object 关联模型对象
$table string 中间表名
$foreignKey string 关联模型关联键
$localKey string 当前模型关联键
$condition array 关联查询条件
Результат Think\Db\Query | string

detach() публичный метод

解除关联的一个中间表数据
public detach ( integer | array $data, boolean $relationDel = false ) : integer
$data integer | array 数据 可以使用关联对象的主键
$relationDel boolean 是否同时删除关联表数据
Результат integer

eagerlyManyToMany() защищенный метод

多对多 关联模型预查询
protected eagerlyManyToMany ( object $model, array $where, string $relation, string $subRelation = '' ) : array
$model object 关联模型对象
$where array 关联预查询条件
$relation string 关联名
$subRelation string 子关联
Результат array

eagerlyOneToMany() защищенный метод

一对多 关联模型预查询
protected eagerlyOneToMany ( object $model, array $where, string $relation, string $subRelation = '', boolean $closure = false ) : array
$model object 关联模型对象
$where array 关联预查询条件
$relation string 关联名
$subRelation string 子关联
$closure boolean
Результат array

eagerlyResult() публичный метод

预载入关联查询 返回模型对象
public eagerlyResult ( Model $result, string $relation, string $class = '' ) : Model
$result think\Model 数据对象
$relation string 关联名
$class string 数据集对象名 为空表示数组
Результат think\Model

eagerlyResultSet() публичный метод

预载入关联查询 返回数据集
public eagerlyResultSet ( array $resultSet, string $relation, string $class = '' ) : array
$resultSet array 数据集
$relation string 关联名
$class string 数据集对象名 为空表示数组
Результат array

getRelation() публичный метод

获取关联数据
public getRelation ( $name )

getRelationInfo() публичный метод

获取当前关联信息
public getRelationInfo ( string $name = '' ) : array | string | integer
$name string 关联信息
Результат array | string | integer

hasMany() публичный метод

HAS MANY 关联定义
public hasMany ( string $model, string $foreignKey, string $localKey, array $alias )
$model string 模型名
$foreignKey string 关联外键
$localKey string 关联主键
$alias array 别名定义

hasManyThrough() публичный метод

HAS MANY 远程关联定义
public hasManyThrough ( string $model, string $through, $foreignKey, $throughKey, string $localKey, array $alias )
$model string 模型名
$through string 中间模型名
$localKey string 关联主键
$alias array 别名定义

hasOne() публичный метод

HAS ONE 关联定义
public hasOne ( string $model, string $foreignKey, string $localKey, array $alias = [], string $joinType = 'INNER' )
$model string 模型名
$foreignKey string 关联外键
$localKey string 关联主键
$alias array 别名定义
$joinType string JOIN类型

match() защищенный метод

一对一 关联模型预查询拼装
protected match ( string $model, string $relation, Model &$result ) : void
$model string 模型名称
$relation string 关联名
$result think\Model 模型对象实例
Результат void

resultSetBuild() защищенный метод

封装关联数据集
protected resultSetBuild ( array $resultSet, string $class = '' ) : mixed
$resultSet array 数据集
$class string 数据集类名
Результат mixed

save() публичный метод

保存(新增)当前关联数据对象
public save ( mixed $data, array $pivot = [] ) : integer
$data mixed 数据 可以使用数组 关联模型对象 和 关联对象的主键
$pivot array 中间表额外数据
Результат integer

saveAll() публичный метод

批量保存当前关联数据对象
public saveAll ( array $dataSet, array $pivot = [] ) : integer
$dataSet array 数据集
$pivot array 中间表额外数据
Результат integer

setAlias() публичный метод

设置当前关联定义的数据表别名
public setAlias ( array $alias )
$alias array 别名定义

Описание свойств

$alias защищенное свойство

数据表别名
protected $alias

$foreignKey защищенное свойство

关联表外键
protected $foreignKey

$joinType защищенное свойство

当前关联的JOIN类型
protected $joinType

$localKey защищенное свойство

关联表主键
protected $localKey

$middle защищенное свойство

中间表模型
protected $middle

$model защищенное свойство

当前关联的模型类
protected $model

$parent защищенное свойство

父模型对象
protected $parent

$query защищенное свойство

关联模型查询对象
protected $query

$throughKey защищенное свойство

中间关联表外键
protected $throughKey

$type защищенное свойство

当前关联类型
protected $type

$where защищенное свойство

关联查询条件
protected $where