Skip to content

Commit 94d34d6

Browse files
committed
修正chunk方法没有主键的bug
1 parent fae382c commit 94d34d6

File tree

1 file changed

+5
-11
lines changed

1 file changed

+5
-11
lines changed

src/db/Query.php

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -558,18 +558,13 @@ public function chunk(int $count, callable $callback, string | array | null $col
558558

559559
$options = $this->getOptions();
560560
$column = $column ?: $this->getPk();
561+
$bind = $this->bind;
561562

562-
if (isset($options['order'])) {
563-
unset($options['order']);
564-
}
565-
566-
$bind = $this->bind;
567-
568-
if (is_array($column)) {
563+
if ($this->getOption('order') || !is_string($column)) {
569564
$times = 1;
570-
$query = $this->options($options)->page($times, $count);
565+
$resultSet = $this->options($options)->page($times, $count)->select();
571566
} else {
572-
$query = $this->options($options)->limit($count);
567+
$resultSet = $this->options($options)->order($column, $order)->limit($count)->select();
573568

574569
if (str_contains($column, '.')) {
575570
[$alias, $key] = explode('.', $column);
@@ -578,8 +573,6 @@ public function chunk(int $count, callable $callback, string | array | null $col
578573
}
579574
}
580575

581-
$resultSet = $query->order($column, $order)->select();
582-
583576
while (true) {
584577
if (false === call_user_func($callback, $resultSet)) {
585578
return false;
@@ -619,6 +612,7 @@ public function lazy(int $count = 1000, ?string $column = null, string $order =
619612
if ($count < 1) {
620613
throw new Exception('The chunk size should be at least 1');
621614
}
615+
622616
$class = $this->model ? ModelLazyCollection::class : LazyCollection::class;
623617
return new $class(function () use ($count, $column, $order) {
624618
$limit = (int) $this->getOption('limit', 0);

0 commit comments

Comments
 (0)