Ecto.Preloader v0.1.0 Ecto.Preloader View Source

Ecto.Preloader is a module for preloading using joins.

It is more efficient than calling Ecto.Query.Repo.preload, as that results in extra queries.

Join/Preload combination is already supported by Ecto, but it's requires a bit of boilerplate.

This module simplifies it a bit.

Example using Ecto join+assoc+preload

Invoice
|> join(:left, [i], assoc(i, :customer), as: :customer)
|> join(:left, [i], assoc(i, :lines), as: :lines)
|> preload([lines: l, customers: c], lines: l, customer: c)
|> Repo.all()

Example using Ecto.Preloader

import Ecto.Preloader

Invoice
|> preload_join(:customer)
|> preload_join(:lines)
|> Repo.all()

Link to this section Summary

Link to this section Functions

Link to this macro

preload_join(query, association)

View Source (macro)