Is it possible to create objects in multiple tables AND establish relationships within the same form?

Hello! New here but have a question about saving values to different tables within the same form.

I have an “Exercise” table that has many to many relations with the “Muscles” table. I have this set up and working (so I can see the Muscles worked in each Exercise detail page). I did this by using a third table called ExMuscles, which includes muscle and exercise pairings, where each exercise may have more than one row if there is more than one muscle contributing to that exercise.

Here is where I’m stuck:

I also have a numerical column within each row of the “shared” ExMuscles table that I’m using to “score” the “contribution” of that muscle in the specific exercise (e.g., both pecs and triceps are active muscles in a bench press but the pecs generally contribute more than the triceps and will therefore receive a higher numerical “score”).

What I want to do is be able to create a form where I can add a new exercise, while also adding any active muscles of the exercise (via a choice component pulling from the muscles table) AND each of the muscle’s contribution scores to the exercise. Ideally I would like “dynamic” input fields for each muscle-contribution “pair”, that would only appear each time I clicked a button within the body of the form to add more for that exercise.

Where I am confused is I’m not sure how to create the form to save a new exercise within the Exercise table AND set the active muscles (and contribution value) relationships to create a new row in the ExMuscles table. It seems on form submit it would need to first save the exercise THEN save the relationship and then contribution value. Is there a way to accomplish this?

Thank you!

I would just do it after you add the exercise. That way, you would be able to reliably add the rowID of the exercise to the ExMuscles table, while easily add the muscle itself, and the numerical value.

Thank you for your response! I was thinking I could do that with a custom action upon hitting submit by just saving to the Exercise table first (pulling from the applicable fields in the form), but I can’t figure out how to save to the ExMuscles table in the next step of the action because it won’t provide me the option to set the fields in the form that apply to that table. I also noticed that when creating the choice field for the muscles list within the form itself, that it won’t even let me set the ExMuscles table as a destination which I’m assuming is why it won’t let me link those fields to that table within the action. From what I am reading, I believe this is possible but can’t figure out what I’m doing wrong.