Load artists when showing a record
This commit is contained in:
@@ -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.
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
|
||||
<.list>
|
||||
<:item title="Type"><%= @record.type %></:item>
|
||||
<:item title="Artists"><%= Enum.map(@record.artists, fn a -> a.name end) %></:item>
|
||||
<:item title="Title"><%= @record.title %></:item>
|
||||
<:item title="Musicbrainz"><%= @record.musicbrainz_id %></:item>
|
||||
<:item title="Year"><%= @record.year %></:item>
|
||||
|
||||
Reference in New Issue
Block a user