Relation
trait Relation
实体关联处理
Methods
mixed
getOption(string $opt = null)
获取选项
static;
setOption(string $opt, mixed $value)
设置选项
static Entity
has(string $relation, mixed $operator = '>=', int $count = 1, array $where = [])
查询已存在的关联
static Entity
static Entity
doesntHave(string $relation, mixed $operator = '>=', int $count = 1, array $where = [])
查询不存在的关联
static Entity
whereDoesntHave(string $relation, array|Closure $where = null, mixed $operator = '>=', int $count = 1)
带上条件查询不存在的关联(本方法执行的where会自动带上关联实体的表前缀)
bool
associatedPreloadWithJoin(Entity $entity, string $relation, mixed $subField = '*', string $joinType = '', Closure $closure = null, bool $addMainTable = false)
预载入关联查询 JOIN方式
void
collectAssociatedPreload(array $resultSet, array $relations, bool $join = false)
预载入关联查询 返回数据集
hasManyThrough(string $entity, string $through, string $foreignKey = '', string $throughKey = '', string $localKey = '', string $throughPk = '')
HAS MANY 远程关联定义
hasOneThrough(string $entity, string $through, string $foreignKey = '', string $throughKey = '', string $localKey = '', string $throughPk = '')
HAS ONE 远程关联定义
belongsToMany(string $entity, string $middle = '', string $foreignKey = '', string $localKey = '')
BELONGS TO MANY 关联定义
string
parseEntity(string $entity)
解析实体的完整命名空间
string
getForeignKey(string $name)
获取实体的默认外键名
void
writeWithSave()
关联新增、写入 OneToOne
void
writeWithDelete()
关联删除 OneToOne、OneToMany
static Relation
static Relation
withAggregate(array|string $relations, string $aggregate = 'count', string $aggregateField = '*', mixed $columns = '*')
关联统计
static Relation
withCount(string|array $relation, string $aggregateField = '*', mixed $columns = '*')
关联统计
static Relation
withSum(string|array $relation, string $aggregateField, mixed $columns = '*')
关联统计Sum
static Relation
withMax(string|array $relation, string $aggregateField, mixed $columns = '*')
关联统计Max
static Relation
withMin(string|array $relation, string $aggregateField, mixed $columns = '*')
关联统计Min
static Relation
withAvg(string|array $relation, string $aggregateField, mixed $columns = '*')
关联统计Avg
relationAggregate(Entity $entity, array $relations, string $aggregate = 'sum', string $aggregateField = '*')
关联聚合
Details
at line 62
mixed
getOption(string $opt = null)
获取选项
at line 76
static;
setOption(string $opt, mixed $value)
设置选项
at line 89
Relation
writeWith(array $writeWithRelation)
关联数据写
at line 114
static Entity
has(string $relation, mixed $operator = '>=', int $count = 1, array $where = [])
查询已存在的关联
at line 137
static Entity
whereHas(string $relation, array|Closure $where = null, mixed $operator = '>=', int $count = 1)
带上条件查询已存在的关联(本方法执行的where会自动带上关联实体的表前缀)
at line 152
static Entity
doesntHave(string $relation, mixed $operator = '>=', int $count = 1, array $where = [])
查询不存在的关联
at line 175
static Entity
whereDoesntHave(string $relation, array|Closure $where = null, mixed $operator = '>=', int $count = 1)
带上条件查询不存在的关联(本方法执行的where会自动带上关联实体的表前缀)
at line 192
bool
associatedPreloadWithJoin(Entity $entity, string $relation, mixed $subField = '*', string $joinType = '', Closure $closure = null, bool $addMainTable = false)
预载入关联查询 JOIN方式
at line 214
void
collectAssociatedPreload(array $resultSet, array $relations, bool $join = false)
预载入关联查询 返回数据集
at line 253
HasOne
hasOne(string $entity, string $foreignKey = '', string $localKey = '')
HAS ONE 关联定义
at line 272
BelongsTo
belongsTo(string $entity, string $foreignKey = '', string $localKey = '')
BELONGS TO 关联定义
at line 290
HasMany
hasMany(string $entity, string $foreignKey = '', string $localKey = '')
HAS MANY 关联定义
at line 312
HasManyThrough
hasManyThrough(string $entity, string $through, string $foreignKey = '', string $throughKey = '', string $localKey = '', string $throughPk = '')
HAS MANY 远程关联定义
at line 338
HasOneThrough
hasOneThrough(string $entity, string $through, string $foreignKey = '', string $throughKey = '', string $localKey = '', string $throughPk = '')
HAS ONE 远程关联定义
at line 362
BelongsToMany
belongsToMany(string $entity, string $middle = '', string $foreignKey = '', string $localKey = '')
BELONGS TO MANY 关联定义
at line 383
MorphOne
morphOne(string $entity, string|array $morph = null, string $type = '')
MORPH One 关联定义
at line 407
MorphMany
morphMany(string $entity, string|array $morph = null, string $type = '')
MORPH MANY 关联定义
at line 431
MorphTo
morphTo(string|array $morph = null, array $alias = [])
MORPH TO 关联定义
at line 452
protected string
parseEntity(string $entity)
解析实体的完整命名空间
at line 471
string
getForeignKey(string $name)
获取实体的默认外键名
at line 484
protected void
writeWithSave()
关联新增、写入 OneToOne
at line 501
protected void
writeWithDelete()
关联删除 OneToOne、OneToMany
at line 542
static Relation
withJoin(array|string $with, Entity $entity = null, string $joinType = 'inner')
关联预载入 JOIN方式-只适用于HasOne和BelongsTo
at line 578
static protected Relation
withAggregate(array|string $relations, string $aggregate = 'count', string $aggregateField = '*', mixed $columns = '*')
关联统计
at line 597
static Relation
withCount(string|array $relation, string $aggregateField = '*', mixed $columns = '*')
关联统计
at line 611
static Relation
withSum(string|array $relation, string $aggregateField, mixed $columns = '*')
关联统计Sum
at line 625
static Relation
withMax(string|array $relation, string $aggregateField, mixed $columns = '*')
关联统计Max
at line 639
static Relation
withMin(string|array $relation, string $aggregateField, mixed $columns = '*')
关联统计Min
at line 653
static Relation
withAvg(string|array $relation, string $aggregateField, mixed $columns = '*')
关联统计Avg