关联预载入查询支持关联统计

This commit is contained in:
thinkphp
2016-12-22 12:52:13 +08:00
parent cd57d97f36
commit 9657ee01b1
5 changed files with 52 additions and 16 deletions

View File

@@ -1620,10 +1620,11 @@ class Query
/**
* 设置关联查询JOIN预查询
* @access public
* @param string|array $with 关联方法名称
* @param string|array $with 关联方法名称
* @param bool $count 是否统计
* @return $this
*/
public function with($with)
public function with($with, $count = false)
{
if (empty($with)) {
return $this;
@@ -1662,7 +1663,8 @@ class Query
}
}
$this->via();
$this->options['with'] = $with;
$this->options['with'] = $with;
$this->options['count'] = $count;
return $this;
}
@@ -2017,7 +2019,7 @@ class Query
}
if (!empty($options['with'])) {
// 预载入
$result->eagerlyResultSet($resultSet, $options['with'], is_object($resultSet) ? get_class($resultSet) : '');
$result->eagerlyResultSet($resultSet, $options['with'], is_object($resultSet) ? get_class($resultSet) : '', !empty($options['count']) ? true : false);
}
}
// 模型数据集转换
@@ -2113,7 +2115,7 @@ class Query
}
// 预载入查询
if (!empty($options['with'])) {
$data->eagerlyResult($data, $options['with'], is_object($result) ? get_class($result) : '');
$data->eagerlyResult($data, $options['with'], is_object($result) ? get_class($result) : '', !empty($options['count']) ? true : false);
}
// 关联统计
if (!empty($options['with_count'])) {