iex(5)> results = Repo.one(query)
18:49:30.301 [debug] QUERY OK source="tracks" db=2.5ms decode=1.7ms
SELECT t0."id", t0."title", t0."duration", t0."index", t0."number_of_plays", t0."inserted_at", t0."updated_at", t0."album_id" FROM "tracks" AS t0 WHERE (t0."id" = $1) [29]
18:49:30.308 [debug] QUERY OK source="albums" db=1.7ms
SELECT a0."id", a0."title", a0."inserted_at", a0."updated_at", a0."artist_id", a0."id" FROM "albums" AS a0 WHERE (a0."id" = $1) [4]
18:49:30.310 [debug] QUERY OK source="artists" db=1.7ms
SELECT a0."id", a0."name", a0."birth_date", a0."death_date", a0."inserted_at", a0."updated_at", a0."id" FROM "artists" AS a0 WHERE (a0."id" = $1) [2]
18:49:30.314 [debug] QUERY OK source="albums" db=1.7ms
SELECT a0."id", a0."title", a0."inserted_at", a0."updated_at", a0."artist_id", a0."artist_id" FROM "albums" AS a0 WHERE (a0."artist_id" = $1) ORDER BY a0."artist_id" [2]
%MusicDB.Track{
__meta__: #Ecto.Schema.Metadata<:loaded, "tracks">,
album: %MusicDB.Album{
__meta__: #Ecto.Schema.Metadata<:loaded, "albums">,
artist: %MusicDB.Artist{
__meta__: #Ecto.Schema.Metadata<:loaded, "artists">,
albums: [
%MusicDB.Album{
__meta__: #Ecto.Schema.Metadata<:loaded, "albums">,
artist: #Ecto.Association.NotLoaded<association :artist is not loaded>,
artist_id: 2,
genres: #Ecto.Association.NotLoaded<association :genres is not loaded>,
id: 4,
inserted_at: ~N[2018-06-16 20:29:41.493342],
title: "Portrait In Jazz",
tracks: #Ecto.Association.NotLoaded<association :tracks is not loaded>,
updated_at: ~N[2018-06-16 20:29:41.493348]
},
%MusicDB.Album{
__meta__: #Ecto.Schema.Metadata<:loaded, "albums">,
artist: #Ecto.Association.NotLoaded<association :artist is not loaded>,
artist_id: 2,
genres: #Ecto.Association.NotLoaded<association :genres is not loaded>,
id: 3,
inserted_at: ~N[2018-06-16 20:29:41.483682],
title: "You Must Believe In Spring",
tracks: #Ecto.Association.NotLoaded<association :tracks is not loaded>,
updated_at: ~N[2018-06-16 20:29:41.483713]
}
],
birth_date: nil,
death_date: nil,
id: 2,
inserted_at: ~N[2018-06-16 20:29:41.481934],
name: "Bill Evans",
tracks: #Ecto.Association.NotLoaded<association :tracks is not loaded>,
updated_at: ~N[2018-06-16 20:29:41.481940]
},
artist_id: 2,
genres: #Ecto.Association.NotLoaded<association :genres is not loaded>,
id: 4,
inserted_at: ~N[2018-06-16 20:29:41.493342],
title: "Portrait In Jazz",
tracks: #Ecto.Association.NotLoaded<association :tracks is not loaded>,
updated_at: ~N[2018-06-16 20:29:41.493348]
},
album_id: 4,
duration: 325,
duration_string: nil,
id: 29,
index: 9,
inserted_at: ~N[2018-06-16 20:29:41.499008],
number_of_plays: 0,
title: "Blue In Green",
updated_at: ~N[2018-06-16 20:29:41.499013]
}
iex(6)> forget_assoc = fn ecto_struct, field, cardinality ->
...(6)> not_loaded = %Ecto.Association.NotLoaded{
...(6)> __field__: field,
...(6)> __owner__: ecto_struct.__struct__,
...(6)> __cardinality__: cardinality
...(6)> }
...(6)> Map.put(ecto_struct, field, not_loaded)
...(6)> end
#Function<18.127694169/3 in :erl_eval.expr/5>
iex(7)> albums = results.album.artist.albums
[
%MusicDB.Album{
__meta__: #Ecto.Schema.Metadata<:loaded, "albums">,
artist: #Ecto.Association.NotLoaded<association :artist is not loaded>,
artist_id: 2,
genres: #Ecto.Association.NotLoaded<association :genres is not loaded>,
id: 4,
inserted_at: ~N[2018-06-16 20:29:41.493342],
title: "Portrait In Jazz",
tracks: #Ecto.Association.NotLoaded<association :tracks is not loaded>,
updated_at: ~N[2018-06-16 20:29:41.493348]
},
%MusicDB.Album{
__meta__: #Ecto.Schema.Metadata<:loaded, "albums">,
artist: #Ecto.Association.NotLoaded<association :artist is not loaded>,
artist_id: 2,
genres: #Ecto.Association.NotLoaded<association :genres is not loaded>,
id: 3,
inserted_at: ~N[2018-06-16 20:29:41.483682],
title: "You Must Believe In Spring",
tracks: #Ecto.Association.NotLoaded<association :tracks is not loaded>,
updated_at: ~N[2018-06-16 20:29:41.483713]
}
]
iex(8)> track = forget_assoc.(results, :album, :one)
%MusicDB.Track{
__meta__: #Ecto.Schema.Metadata<:loaded, "tracks">,
album: #Ecto.Association.NotLoaded<association :album is not loaded>,
album_id: 4,
duration: 325,
duration_string: nil,
id: 29,
index: 9,
inserted_at: ~N[2018-06-16 20:29:41.499008],
number_of_plays: 0,
title: "Blue In Green",
updated_at: ~N[2018-06-16 20:29:41.499013]
}
iex(9)> result = %{track: track, albums: albums}
%{
albums: [
%MusicDB.Album{
__meta__: #Ecto.Schema.Metadata<:loaded, "albums">,
artist: #Ecto.Association.NotLoaded<association :artist is not loaded>,
artist_id: 2,
genres: #Ecto.Association.NotLoaded<association :genres is not loaded>,
id: 4,
inserted_at: ~N[2018-06-16 20:29:41.493342],
title: "Portrait In Jazz",
tracks: #Ecto.Association.NotLoaded<association :tracks is not loaded>,
updated_at: ~N[2018-06-16 20:29:41.493348]
},
%MusicDB.Album{
__meta__: #Ecto.Schema.Metadata<:loaded, "albums">,
artist: #Ecto.Association.NotLoaded<association :artist is not loaded>,
artist_id: 2,
genres: #Ecto.Association.NotLoaded<association :genres is not loaded>,
id: 3,
inserted_at: ~N[2018-06-16 20:29:41.483682],
title: "You Must Believe In Spring",
tracks: #Ecto.Association.NotLoaded<association :tracks is not loaded>,
updated_at: ~N[2018-06-16 20:29:41.483713]
}
],
track: %MusicDB.Track{
__meta__: #Ecto.Schema.Metadata<:loaded, "tracks">,
album: #Ecto.Association.NotLoaded<association :album is not loaded>,
album_id: 4,
duration: 325,
duration_string: nil,
id: 29,
index: 9,
inserted_at: ~N[2018-06-16 20:29:41.499008],
number_of_plays: 0,
title: "Blue In Green",
updated_at: ~N[2018-06-16 20:29:41.499013]
}
}
iex(10)>