lode/preload

The preload specification — what repo.preload and query.preload accept.

Mirrors Ecto’s preload([:comments, comments: :author]): a list of association names to load, each optionally with its own nested preloads.

[preload.one(“comments”)] // :comments [preload.nest(“comments”, [preload.one(“author”)])] // [comments: :author]

Each preload also carries a Strategy: Batched (the default — one extra query per association, N+1-free) or Joined (load the association in the same query via a JOIN; Ecto’s preload-through-a-join-binding). Joined only takes effect through query.preload + repo.all/repo.one on a SQL adapter, and only for has_many/has_one associations (see repo.all).

Types

pub type Preload {
  Preload(
    name: String,
    nested: List(Preload),
    strategy: Strategy,
  )
}

Constructors

How an association is loaded relative to its parent query.

pub type Strategy {
  Batched
  Joined
}

Constructors

  • Batched

    A separate batched query (column IN (parent keys)); the default.

  • Joined

    A JOIN in the parent’s own query, split back out by column prefix.

Values

pub fn join(name: String) -> Preload

Preload an association in the parent query via a JOIN (Ecto’s preload through a join binding). SQL adapters only, has_many/has_one only; nested preloads on the joined children still run batched. See repo.all.

pub fn join_nest(
  name: String,
  nested nested: List(Preload),
) -> Preload

Like join, then preload nested on the joined children (batched).

pub fn nest(
  name: String,
  nested nested: List(Preload),
) -> Preload

Preload an association by name, then preload nested on the loaded children (batched).

pub fn one(name: String) -> Preload

Preload an association by name (no nesting), batched.

Search Document