PHP 클래스 think\model\Relation

파일 보기 프로젝트 열기: top-think/framework

보호된 프로퍼티들

프로퍼티 타입 설명
$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