mardi 12 juillet 2016

Eloquent model Query Builder result and a race condition

Eloquent model returns a result.

$result = MyModel::where(...)->get();

Then some calculations gain a subset of ids out of the initial selection that should be deleted from DB.

$pidsToDelete = [1,2,3];

While the calculations are processed more records might appear in DB that match the initial selection. However, I want to be sure to delete only those from the initial selection.

By doing

$result->whereIn('pid', $idsToDelete)->delete();

can I be sure its the initial selection, and not a new query result, that I am working with?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire