Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Multi.new()
|> Multi.insert(:item_without_hash_id, changeset)
|> Multi.run(:playlist, fn _repo, %{item_without_hash_id: playlist} ->
playlist
|> Playlist.changeset_generate_hash_id()
|> Repo.update()
end)
# iterate over the localized_titles and add to db
# pass in playlist that was just inserted
|> Multi.run(:add_localized_titles, fn _repo, %{playlist: playlist} ->
maps =
for title <- localized_titles,
_ = Logger.debug("title #{inspect(%{attributes: title})}"),
{k, v} <- title do
IO.puts("#{k} --> #{v}")
Repo.insert(%PlaylistTitle{
language_id: k,
localizedname: v,
uuid: Ecto.UUID.generate(),
playlist_id: playlist.id
})
end
Logger.debug("maps #{inspect(%{attributes: maps})}")
{:ok, maps}
end)
|> Repo.transaction()
|> case do
{:ok, %{playlist: playlist}} ->
{:ok, playlist}
{:error, _, error, _} ->
{:error, error}
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment