Question on creation with Many-to-Many relationships

Hello!
One probably silly question:
Is it possible to have an Action for a data type that isn’t a model? I have a few models:

  • Exercise
  • MuscleGroup
  • ExercisesMuscleGroup (link table between the two above, it is a many-to-many relationshit).

Ideally, I’d like to submit a form that would create an Exercise, and also create the relevant rows in the ExercisesMuscleGroup link table.
I can do this all manually by passing in a custom parambut I wanted to see if I could leverage the type system to do this kind of work for me.

Does anyone have any tips on how to approach this in a nice manner? I’ve tried a few approaches and it seems like they pull me very much out of my depth.
You can see the PR where I’m attempting this here.

I would also like to mention that this has been by far the most fun I’ve had playing around with types!
I’ve never really had a reason to, but now, I find I am learning a LOT!

Thank you for the great work,
Nuno

Hey!

Thanks for the feedback :slight_smile:

There’s no great type safe way to do this in IHP, so going with param is already pretty good.

There is some examples in this repo as well: https://github.com/digitallyinduced/ihp-multi-records-form-example

Oh, thank you! That was the initial idea I had, but I’m glad to see a fully fleshed out example so I can see what I missed.

Thanks again, this has been so much fun!