How do I solve this association problem? [solved]

Hey guys, how would be the best way to do this?

I have an User and Restaurant and User belongs_to Restaurant and Restaurant has_many Users, with that being said. How would be the best way to create both at the same time and associate them? For example…

After the signup of an user (I’m using pow) I want to create the restaurant and assoc with the user. So ideia here is after I signup -> both user and restaurant should exist and be associated.

And if one of them fail both should not be created.

Ok, I made it works so what I did: I used this Multi thing and worked =D

def create_admin_with_restaurant(params) do
    |> Multi.insert(:restaurant, Restaurant.changeset(%Restaurant{}, %{}))
    |>, fn repo, %{restaurant: restaurant} ->
      Ecto.build_assoc(restaurant, :users)
      |> User.changeset(params)
      |> User.changeset_role(%{role: "admin"})
      |> repo.insert()
    |> Repo.transaction()