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?