发现类似$model->group('area_id')->paginate(2)的分页不对,修改\thinkphp\library\think\Query的count方法(494行)如下:
public function count($field = '*')
{
$options = $this->getOptions();
/*
* 修复group情况下count不正确
* @author 王荣 老倪
* @version 2017.1.19
*/
if($options['group']){
$bind = $this->bind;
//构建lists sql
$lists = $this->options($options)->field('count(*)')->bind($bind)->fetchSql(true)->select();
//构建子查询统计sql
$sql = "select count(*) as tp_count from ($lists) a";
$resultSet = $this->query($sql, $bind);
return $resultSet[0]['tp_count'];
}
return $this->value('COUNT(' . $field . ') AS tp_count', 0);
}https://www.olcms.com/2036 最佳答案