$parent
$parent :
Class Relation
$model : \think\Model
$query : \think\db\Query
getParent() : \think\Model
获取关联的所属模型
getModel() : \think\Model
获取当前的关联模型类的实例
__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) : \think\Collection
延迟获取关联数据
| string | $subRelation | 子关联名 |
| \Closure | $closure | 闭包查询条件 |
select(mixed $data = null) : \think\Collection
重载select方法
| mixed | $data |
find(mixed $data = null) : \think\Model
重载find方法
| mixed | $data |
selectOrFail(array|string|\think\db\Query|\Closure $data = null) : \think\Collection
查找多条记录 如果不存在则抛出异常
| array|string|\think\db\Query|\Closure | $data |
findOrFail(array|string|\think\db\Query|\Closure $data = null) : \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, string $aggregate = 'count', string $field = '*') : integer
关联统计
| \think\Model | $result | 数据对象 |
| \Closure | $closure | 闭包 |
| string | $aggregate | 聚合查询方法 |
| string | $field | 字段 |
save(mixed $data, array $pivot = array()) : array|\think\model\Pivot
保存(新增)当前关联数据对象
| mixed | $data | 数据 可以使用数组 关联模型对象 和 关联对象的主键 |
| array | $pivot | 中间表额外数据 |
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\model\relation\Paginator $models)
合成中间表模型
| array|\think\Collection|\think\model\relation\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 | 关联查询条件 |