PHP Class think\model\Relation

Datei anzeigen Open project: top-think/framework

Protected Properties

Property Type Description
$alias 数据表别名
$foreignKey 关联表外键
$joinType 当前关联的JOIN类型
$localKey 关联表主键
$middle 中间表模型
$model 当前关联的模型类
$parent 父模型对象
$query 关联模型查询对象
$throughKey 中间关联表外键
$type 当前关联类型
$where 关联查询条件

Public Methods

Method Description
__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 ) 设置当前关联定义的数据表别名

Protected Methods

Method Description
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 封装关联数据集

Method Details

__call() public method

public __call ( $method, $args )

__construct() public method

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

attach() public method

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

belongsTo() public method

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() public method

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() protected method

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 关联查询条件
return Think\Db\Query | string

detach() public method

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

eagerlyManyToMany() protected method

多对多 关联模型预查询
protected eagerlyManyToMany ( object $model, array $where, string $relation, string $subRelation = '' ) : array
$model object 关联模型对象
$where array 关联预查询条件
$relation string 关联名
$subRelation string 子关联
return array

eagerlyOneToMany() protected method

一对多 关联模型预查询
protected eagerlyOneToMany ( object $model, array $where, string $relation, string $subRelation = '', boolean $closure = false ) : array
$model object 关联模型对象
$where array 关联预查询条件
$relation string 关联名
$subRelation string 子关联
$closure boolean
return array

eagerlyResult() public method

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

eagerlyResultSet() public method

预载入关联查询 返回数据集
public eagerlyResultSet ( array $resultSet, string $relation, string $class = '' ) : array
$resultSet array 数据集
$relation string 关联名
$class string 数据集对象名 为空表示数组
return array

getRelation() public method

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

getRelationInfo() public method

获取当前关联信息
public getRelationInfo ( string $name = '' ) : array | string | integer
$name string 关联信息
return array | string | integer

hasMany() public method

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

hasManyThrough() public method

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

hasOne() public method

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 method

一对一 关联模型预查询拼装
protected match ( string $model, string $relation, Model &$result ) : void
$model string 模型名称
$relation string 关联名
$result think\Model 模型对象实例
return void

resultSetBuild() protected method

封装关联数据集
protected resultSetBuild ( array $resultSet, string $class = '' ) : mixed
$resultSet array 数据集
$class string 数据集类名
return mixed

save() public method

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

saveAll() public method

批量保存当前关联数据对象
public saveAll ( array $dataSet, array $pivot = [] ) : integer
$dataSet array 数据集
$pivot array 中间表额外数据
return integer

setAlias() public method

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

Property Details

$alias protected_oe property

数据表别名
protected $alias

$foreignKey protected_oe property

关联表外键
protected $foreignKey

$joinType protected_oe property

当前关联的JOIN类型
protected $joinType

$localKey protected_oe property

关联表主键
protected $localKey

$middle protected_oe property

中间表模型
protected $middle

$model protected_oe property

当前关联的模型类
protected $model

$parent protected_oe property

父模型对象
protected $parent

$query protected_oe property

关联模型查询对象
protected $query

$throughKey protected_oe property

中间关联表外键
protected $throughKey

$type protected_oe property

当前关联类型
protected $type

$where protected_oe property

关联查询条件
protected $where