Loading schemas and their associations

By default, Ecto doesn't load any associations for us. If we retrieve an Owner schema, Ecto will tell you that the files field isn't loaded yet:

iex> owner = Repo.get!(Owner, "13KvtrMQ9uRB8MqkJpKSSQZxnBa")11:15:18.878 [debug] QUERY OK source="users" db=1.2ms decode=2.8msSELECT u0."id", u0."email" FROM "users" AS u0 WHERE (u0."id" = $1) ["13KvtrMQ9uRB8MqkJpKSSQZxnBa"]%ElixirDrip.Storage.Owner{  __meta__: #Ecto.Schema.Metadata<:loaded, "users">,  email: "jose@hey.ho",  files: #Ecto.Association.NotLoaded<association :files is not loaded>,  id: "13KvtrMQ9uRB8MqkJpKSSQZxnBa"}

If you want to access their files, you need to explicitly call the Repo.preload/2 callback with the schema and the field to load:

iex> ...

Get Mastering Elixir now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.