For me, I have to admit, I don’t think I have had too many situations where I am calling in more than a single foreign key from the last table, so I generally just have the insert steps stacking.
Database Connection
Security Provider
Security Restrict
Database Insert 1 - Which is inserting to an auto incrementing row in its table
Database Insert 2 - Where to foreign key is assigned the auto incremented ID from the first table
Even in situations where I have had up to 3 Foreign Keys going into a certain table, they have still followed a similar path, here is an example
I have a form on my page with 3 fields, fieldA, fieldB, fieldC inserting into 3 different tables linked by FKs
tableA - idA, fieldA
tableB - idB, fieldB, FK_idA
tableC - idC, fieldC, FK_idA, FK_idB
The idA, idB, idC all get auto generated from an auto increment primary key
Insert Step 1 takes fieldA from the form
Insert Step 2 takes fieldB from the form and FK_idA as the identity of the first insert
Insert Step 3 takes fieldC from the form and FK_idA as the identity of the first insert & FK_idB as the identity of the second insert.
I assume in your scenario the user_id has already been generated long before this insert ever takes place which is why it is a little confusing. Try consider a few ideas to get around that.
You could try get the user_id from the security provider identity if that matches the current logged in user.
OR
You could make sure your form is full of hidden fields that have data already inserted from all the tables so it is easily accessible in all your inserts you need to do. Could also be a single hidden field with an array of data where you just access the parts of the array you need in each insert.
OR
You could have a server action where you have inserts and queries, so after insert 1 there is nothing stopping adding a query filtered by the identity of the first insert which sets a variable that can be used as part of insert 2
I really hope this makes sense.