# `EctoContext.Query`
[🔗](https://github.com/exfoundry/ecto_context/blob/v0.1.0/lib/ecto_context/query.ex#L1)

Query helpers used by the EEx templates in `priv/templates/ecto_context/`.

These functions are called at runtime from code generated by `EctoContext`.
They handle optional query composition — preloading, ordering, limiting,
selecting, and filtering by association.

# `assoc_where`

```elixir
@spec assoc_where(Ecto.Queryable.t(), module(), atom(), term()) :: Ecto.Query.t()
```

Filters a query by the foreign key of the given association.

Resolves the foreign key via `resolve_foreign_key/2`, then applies a `where` clause.

# `maybe_limit`

```elixir
@spec maybe_limit(Ecto.Queryable.t(), nil | pos_integer()) :: Ecto.Query.t()
```

Conditionally applies a `limit` clause. No-op when `nil`.

# `maybe_order_by`

```elixir
@spec maybe_order_by(Ecto.Queryable.t(), nil | term()) :: Ecto.Query.t()
```

Conditionally applies an `order_by` clause. No-op when `nil`.

# `maybe_preload`

```elixir
@spec maybe_preload(Ecto.Queryable.t(), nil | term()) :: Ecto.Query.t()
```

Conditionally preloads associations. No-op when `nil`.

# `maybe_query`

```elixir
@spec maybe_query(
  Ecto.Queryable.t(),
  nil | (Ecto.Queryable.t() -&gt; Ecto.Queryable.t())
) ::
  Ecto.Queryable.t()
```

Conditionally applies a 1-arity query function. No-op when `nil`.

# `maybe_select`

```elixir
@spec maybe_select(Ecto.Queryable.t(), nil | [atom()]) :: Ecto.Query.t()
```

Conditionally applies a `select` clause. No-op when `nil`.

# `resolve_foreign_key`

```elixir
@spec resolve_foreign_key(module(), atom()) :: atom()
```

Resolves the foreign key field for an association.

Tries Ecto schema reflection first, falls back to `:assoc_id` convention.
This allows `list_for` to work with both regular `belongs_to` and `static_belongs_to`.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
