Load artists when showing a record
This commit is contained in:
@@ -37,7 +37,15 @@ defmodule MusicLibrary.Records do
|
|||||||
** (Ecto.NoResultsError)
|
** (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 """
|
@doc """
|
||||||
Creates a record.
|
Creates a record.
|
||||||
|
|||||||
@@ -10,6 +10,7 @@
|
|||||||
|
|
||||||
<.list>
|
<.list>
|
||||||
<:item title="Type"><%= @record.type %></:item>
|
<: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="Title"><%= @record.title %></:item>
|
||||||
<:item title="Musicbrainz"><%= @record.musicbrainz_id %></:item>
|
<:item title="Musicbrainz"><%= @record.musicbrainz_id %></:item>
|
||||||
<:item title="Year"><%= @record.year %></:item>
|
<:item title="Year"><%= @record.year %></:item>
|
||||||
|
|||||||
Reference in New Issue
Block a user