MDN
4 years ago

Inserting into multiple models and a pivot table

Posted 4 years ago by MDN

I'm trying to create a basic thesaurus. I have a words table, an alternatives table and a alternative_word pivot table.

I have a Word model and an Alternative model each with a belongsToMany realtionship to each other. My form is very simple with just a word field and an alternative field. I know how to insert using one model, but I don't know how to insert into two models and then create the pivot for it. What is the best way of handling this?

Please sign in or create an account to participate in this conversation.