# `Bylaw.Credo.Check.Ecto.NoRepoPreloadAfterQuery`
[🔗](https://github.com/ryanzidago/bylaw/blob/v0.4.0/lib/bylaw/credo/check/ecto/no_repo_preload_after_query.ex#L1)

## Basics

> #### This check is disabled by default. {: .neutral}
>
> [Learn how to enable it](`e:credo:config_file.html#checks`) via `.credo.exs`.

This check has a base priority of `higher` and works with any version of Elixir.

## Explanation

Do not call `Repo.preload` after loading records with `Repo.one` or
`Repo.all`. Prefer composing the preload into the Ecto query so the
preload intent stays visible at the query boundary.

Query-level preloads keep retrieval and association requirements together,
so callers can see the complete database operation and the query can be
reviewed or composed as one unit. They also avoid hiding an additional
database operation after the Repo read has already returned.

## Examples

Avoid:

      query
      |> Repo.one()
      |> Repo.preload([:message])
Prefer:

      query
      |> preload([:message])
      |> Repo.one()

The same rule applies when a local helper hides the `Repo.preload` call:

      query
      |> Repo.one()
      |> preload_message()
Prefer:

      query
      |> preload([:message])
      |> Repo.one()

## Notes

This check uses static AST analysis, so it favors clear source-level patterns over runtime behavior.

## Options

This check has no check-specific options. Configure it with an empty option list.

## Usage

Add this check to Credo's `checks:` list in `.credo.exs`:

```elixir
%{
  configs: [
    %{
      name: "default",
      checks: [
        {Bylaw.Credo.Check.Ecto.NoRepoPreloadAfterQuery, []}
      ]
    }
  ]
}
```

## Check-Specific Parameters

*There are no specific parameters for this check.*

## General Parameters

Like with all checks, [general params](`e:credo:check_params.html`) can be applied.

Parameters can be configured via the [`.credo.exs` config file](`e:credo:config_file.html`).

---

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