July 2018
Intermediate to advanced
574 pages
14h 7m
English
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> ...