mirror of
https://gitee.com/fastadminnet/framework.git
synced 2026-07-03 05:52:48 +08:00
增加关联统计功能
This commit is contained in:
@@ -1666,6 +1666,18 @@ class Query
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 关联统计
|
||||
* @access public
|
||||
* @param string|array $relation 关联方法名
|
||||
* @return $this
|
||||
*/
|
||||
public function withCount($relation)
|
||||
{
|
||||
$this->options['with_count'] = $relation;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 关联预加载中 获取关联指定字段值
|
||||
* example:
|
||||
@@ -1997,6 +2009,10 @@ class Query
|
||||
if (!empty($options['relation'])) {
|
||||
$result->relationQuery($options['relation']);
|
||||
}
|
||||
// 关联统计
|
||||
if (!empty($options['with_count'])) {
|
||||
$result->relationCount($result, $options['with_count']);
|
||||
}
|
||||
$resultSet[$key] = $result;
|
||||
}
|
||||
if (!empty($options['with'])) {
|
||||
@@ -2095,10 +2111,14 @@ class Query
|
||||
if (!empty($options['relation'])) {
|
||||
$data->relationQuery($options['relation']);
|
||||
}
|
||||
// 预载入查询
|
||||
if (!empty($options['with'])) {
|
||||
// 预载入
|
||||
$data->eagerlyResult($data, $options['with'], is_object($result) ? get_class($result) : '');
|
||||
}
|
||||
// 关联统计
|
||||
if (!empty($options['with_count'])) {
|
||||
$data->relationCount($data, $options['with_count']);
|
||||
}
|
||||
}
|
||||
} elseif (!empty($options['fail'])) {
|
||||
$this->throwNotFound($options);
|
||||
|
||||
Reference in New Issue
Block a user