$parent
$parent :
Class Relation
$model : \think\Model
$query : \think\db\Query
getParent() : \think\Model
获取关联的所属模型
getModel() : \think\Model
获取当前的关联模型对象实例
getQuery() : \think\db\Query
获取关联的查询对象
__construct(\think\Model $parent, string $model, string $table, string $foreignKey, string $localKey)
构造函数
| \think\Model | $parent | 上级模型对象 |
| string | $model | 模型名 |
| string | $table | 中间表名 |
| string | $foreignKey | 关联模型外键 |
| string | $localKey | 当前模型关联键 |
getRelation(string $subRelation = '', \Closure $closure = null) : false|\PDOStatement|string|\think\Collection
延迟获取关联数据
| string | $subRelation | 子关联名 |
| \Closure | $closure | 闭包查询条件 |
select(null $data = null) : false|\PDOStatement|string|\think\Collection
重载select方法
| null | $data |
paginate(null $listRows = null, boolean $simple = false, array $config = array()) : \think\Paginator
重载paginate方法
| null | $listRows | |
| boolean | $simple | |
| array | $config |
find(null $data = null) : array|false|\PDOStatement|string|\think\Model
重载find方法
| null | $data |
selectOrFail(array|string|\think\db\Query|\Closure $data = null) : array|\PDOStatement|string|\think\Model
查找多条记录 如果不存在则抛出异常
| array|string|\think\db\Query|\Closure | $data |
findOrFail(array|string|\think\db\Query|\Closure $data = null) : array|\PDOStatement|string|\think\Model
查找单条记录 如果不存在则抛出异常
| array|string|\think\db\Query|\Closure | $data |
has(string $operator = '>=', integer $count = 1, string $id = '*', string $joinType = 'INNER') : \think\db\Query
根据关联条件查询当前模型
| string | $operator | 比较操作符 |
| integer | $count | 个数 |
| string | $id | 关联表的统计字段 |
| string | $joinType | JOIN类型 |
hasWhere(mixed $where = array(), mixed $fields = null) : \think\db\Query
根据关联条件查询当前模型
| mixed | $where | 查询条件(数组或者闭包) |
| mixed | $fields | 字段 |
eagerlyResult(\think\Model $result, string $relation, string $subRelation, \Closure $closure) : void
预载入关联查询(单个数据)
| \think\Model | $result | 数据对象 |
| string | $relation | 当前关联名 |
| string | $subRelation | 子关联名 |
| \Closure | $closure | 闭包 |
relationCount(\think\Model $result, \Closure $closure) : integer
关联统计
| \think\Model | $result | 数据对象 |
| \Closure | $closure | 闭包 |
attach(mixed $data, array $pivot = array()) : array|\think\model\Pivot
附加关联的一个中间表数据
| mixed | $data | 数据 可以使用数组、关联模型对象 或者 关联对象的主键 |
| array | $pivot | 中间表额外数据 |
newPivot(array $data = array(), boolean $isUpdate = false) : \think\model\Pivot
实例化中间表模型
| array | $data | |
| boolean | $isUpdate |
hydratePivot(array|\think\Collection|\think\Paginator $models)
合成中间表模型
| array|\think\Collection|\think\Paginator | $models |
buildQuery() : \think\db\Query
创建关联查询Query对象
belongsToManyQuery(string $foreignKey, string $localKey, array $condition = array()) : \think\db\Query
BELONGS TO MANY 关联查询
| string | $foreignKey | 关联模型关联键 |
| string | $localKey | 当前模型关联键 |
| array | $condition | 关联查询条件 |