I have a situation similar to create and insert 2 associated models.
In my case User has_many Others and Others belongs_to User.
I want to insert a user and an Other in one transaction.
I’m doing a put_assoc from User and it works fine. It generates 2 insert statements of course.
My question is: Do I need to wrap the insert in a Repo.transaction? I have been unable to find any documentation that talks about how the inserts are handled. If I did not wrap the insert function in a transaction, would the 2 sql statements be batched in a single transaction by default or would they be done as 2 separate transactions?
MyModule.Repo.transaction fn -> MyModule.Repo.insert(changeset) end