I need to know the id (and reserve it) for a record that I will insert in database before insert it because I add a product and upload also a image for this product, and the location of image is related to the product id.
I can find the id that will follow, but I need also to keep it “lock” until the product image is uploaded, to be sure that this id isn’t used by another user meanwhile.
You can split this into two operations.
In the first you create everything for the product and get the id. In the second you update the row with the image you’ve uploaded, which can now be saved since you know the ID.