改进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); $column = $column ?: $this->getPk($table);
$bind = $this->bind; $bind = $this->bind;
$resultSet = $this->limit($count)->order($column, 'asc')->select(); $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)) { while (!empty($resultSet)) {
if (false === call_user_func($callback, $resultSet)) { if (false === call_user_func($callback, $resultSet)) {
return false; return false;
} }
$end = end($resultSet); $end = end($resultSet);
$lastId = is_array($end) ? $end[$column] : $end->$column; $lastId = is_array($end) ? $end[$key] : $end->$key;
$resultSet = $this->options($options) $resultSet = $this->options($options)
->limit($count) ->limit($count)
->bind($bind) ->bind($bind)
->where($column, '>', $lastId) ->where($column, '>', $lastId)
->order($column, 'asc') ->order($column, 'asc')
->select(); ->select();
if ($resultSet instanceof Collection) {
$resultSet = $resultSet->all();
}
} }
return true; return true;
} }