laravel-chunk-missing-half-the-results
只要从现在开始努力,最坏不过是大器晚成
Q
I have a problem with Laravel’s ORM Eloquent chunk() method. It misses some results. Here is a test query :
1 | $destinataires = Destinataire::where('statut', '<', 3) |
It gives 124838 results.
But :
1 | $num_dest = Destinataire::where('statut', '<', 3) |
gives 249676, so just TWICE as the first code example.
A
Use chunkById() instead of chunk().
When updating or deleting records inside the chunk callback, any changes to the primary key or foreign keys could affect the chunk query. This could potentially result in records not being included in the chunked results.
1 | DB::table('users')->where('active', false) |
https://stackoverflow.com/questions/32700537/eloquent-chunk-missing-half-the-results