-
Notifications
You must be signed in to change notification settings - Fork 11.6k
Closed
Labels
Description
- Laravel Version: 8.15.0
- PHP Version: 7.4.x
- Database Driver & Version: Mysql 8
Speps to reproduce:
Route::get('/test', function () {
/** @var \DateTimeImmutable $date */
$date = \Illuminate\Support\Facades\Date::now();
\App\Models\User::factory()->create([
'created_at' => $date,
]); // id = 1
\App\Models\User::factory()->create([
'created_at' => $date->subDays(1),
]); // id = 2
\App\Models\User::factory()->create([
'created_at' => $date->subDays(2),
]); // id = 3
\App\Models\User::query()
->orderBy('created_at')
->chunkById(1, function (\Illuminate\Support\Collection $users) {
var_dump($users->pluck('id')->all());
});
});
Actual results:
array (size=1)
0 => int 3
Expected Result
array (size=1)
0 => int 1
array (size=1)
0 => int 2
array (size=1)
0 => int 3
Description
This happens because chunkById
/forPageAfterId
uses:
framework/src/Illuminate/Database/Query/Builder.php
Lines 2131 to 2141 in 8a3aaf4
public function forPageAfterId($perPage = 15, $lastId = 0, $column = 'id') | |
{ | |
$this->orders = $this->removeExistingOrdersFor($column); | |
if (! is_null($lastId)) { | |
$this->where($column, '>', $lastId); | |
} | |
return $this->orderBy($column, 'asc') | |
->limit($perPage); | |
} |
probably it should remove all other "order by"s instead (= call reorder()
).