title: add new row with foreign key when candidate key does not exist yet
body: <p>I find it difficult to find a good title I hope I can explain it better.
  I have two tables</p>
  
  <pre><code>"car" - id, car_id, name
  "car_pictures" - id, fk_car_id, url
  </code></pre>
  
  <p>Obviously a "car" can have several pictures those are linked by the car_id saved as "fk_car_id" in the "car_pictures" table.
  Workflow in a frontend could be:</p>
  
  <pre><code>- you add a new car to the database
  - you add pictures to this car entry
  </code></pre>
  
  <p>If followed this way you first create a new entry in the "car" table. Then you have a "car_id" you can reference in the "car_pictures" table.</p>
  
  <p>But what if you like to change the workflow like this:</p>
  
  <pre><code>- you add a new car
  - you immediately add pictures
  - you save the new car to the database
  </code></pre>
  
  <p>If followed this way you do create the database entry only if the user has finished all "steps". But if you want to add pictures to the car there is no "car_id" for it yet. So you can't reference the id.</p>
  
  <p>What is the usual way to do this if adding the car and adding the pictures are two seperate api calls for example.</p>
  
  <p>It seems I need to clarify what I am doing.
  Let's say I have two api calls:
  www.domain.com/api/car/add/?name=newcar -> for adding a car (ie. adding to the database)
  www.domain.com/api/car/picture/add/?car_id=x -> for adding a picture to a car (ie. handle the upload and put data to the database)</p>
  
  <p>The frontend would look like this:
  A page with a  table with all cars which you can edit and add new pictures to it in another page. Another page to add a new car which also has the possibility to add picture. This would be the same page/form as editing a car only that no car_id is available.</p>
  
  <p>Edit:</p>
  
  <p>I myself can think of several ways to handle this case.</p>
  
  <p>first: create a database entry for a car immediately when the user opens the "add new car" form. that way you always have a car_id. but you have to handle if the user decides to cancel adding a car and need to remove those "dummy" database entries. if something goes wrong there you may end with a lot of empty car entries in the database. maybe the row has a flag that is set when the car is actually "inserted" by the user.</p>
  
  <p>second: insert new pictures with temporary negative fk_car_id and update those rows with the actual car_id if the row is created in the database.</p>
  
  <p>third: save new pictures into a temporary table with a temporary id when there is no car_id yet. then you have to return that temporary id and moved those entries from the temporary table on the creation of a car entry in the database.</p>
  
  <p>But those ideas sound complicated and I hoped there is some best practice way how to do it. Maybe the problem is in my workflow itself and there is a better way to do it. Yet it seems to be a good idea to separate the process of adding a car and adding pictures to a database.</p>