You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// select without id$users = User::select("name")->lazyById(10);
foreach($usersas$user) {
// endless loop (generator) because lazyById will always return elements from the first page
}
So foreach will fall into endless loop and never ends if there are more than 1 page of results.
You can say that it's programmer's responsibility to include id in select but chunkById has this check and lazyById documentation doesn't say anything about id is required.
In the chunkById we have this code which verifies that response has id column.
$lastId = data_get($results->last(), $alias);
if ($lastId === null) {
thrownewRuntimeException("The chunkById operation was aborted because the [{$alias}] column is not present in the query result.");
}
It seems logical to me to add such a check to lazyById as well.
Steps To Reproduce
Create table with 100 records for example
// select without id$users = User::select("name")->lazyById(10);
foreach($usersas$user) {
// endless loop (generator) because lazyById will always return elements from the first page
}