改进Query类对数据集对象以及关联字段排序的支持

This commit is contained in:
thinkphp
2016-11-22 11:08:45 +08:00
parent a10cc77e40
commit 384ce564f9

View File

@@ -2139,19 +2139,30 @@ class Query
$column = $column ?: $this->getPk($table);
$bind = $this->bind;
$resultSet = $this->limit($count)->order($column, 'asc')->select();
if (strpos($column, '.')) {
list($alias, $key) = explode('.', $column);
} else {
$key = $column;
}
if ($resultSet instanceof Collection) {
$resultSet = $resultSet->all();
}
while (!empty($resultSet)) {
if (false === call_user_func($callback, $resultSet)) {
return false;
}
$end = end($resultSet);
$lastId = is_array($end) ? $end[$column] : $end->$column;
$lastId = is_array($end) ? $end[$key] : $end->$key;
$resultSet = $this->options($options)
->limit($count)
->bind($bind)
->where($column, '>', $lastId)
->order($column, 'asc')
->select();
if ($resultSet instanceof Collection) {
$resultSet = $resultSet->all();
}
}
return true;
}