Load artists when showing a record

This commit is contained in:
Claudio Ortolina
2024-09-15 16:16:01 +01:00
parent 99d87a5596
commit e3ff0228cd
2 changed files with 10 additions and 1 deletions
+9 -1
View File
@@ -37,7 +37,15 @@ defmodule MusicLibrary.Records do
** (Ecto.NoResultsError)
"""
def get_record!(id), do: Repo.get!(Record, id)
def get_record!(id) do
q =
from r in Record,
left_join: a in assoc(r, :artists),
preload: [artists: a],
where: r.id == ^id
Repo.one!(q)
end
@doc """
Creates a record.