Is it ok to merge the results of an Ecto.Multi?
eg:
multi =
Multi.new()
|> Multi.insert(:profile, Profile.changeset(%Profile{}, attrs))
|> Multi.run(:user_profile, fn _, %{profile: %{id: id}} ->
UsersProfiles.create_users_profile(%{user_id: user.id, profile_id: id})
end)
|> Multi.run(:teacher, fn _, %{profile: %{id: id}} ->
Teachers.create_teacher(Map.put(attrs.teacher, :profile_id, id))
end)
|> Repo.transaction()
{:ok, %{profile: profile, teacher: teacher}} = multi
%Profile{profile | teacher: teacher}
Ecto.Multi would return the values like this:
{:ok, %{
profile: %Profile{},
user_profile: %UserProfile{},
teacher: %Teacher{}
}}
But because I’m using Absinthe I need teacher to be within the profile as the default/auto resolver can get the teacher fields.