> ## Documentation Index
> Fetch the complete documentation index at: https://fluxcrud.mahimai.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# DataLoader (N+1)

> Solving the N+1 select problem

## The Problem

Fetching a list of posts and then fetching the author for each post in a loop causes the "N+1 Problem":

```python theme={null}
posts = await post_repo.get_multi() # 1 Query
for post in posts:
    # N Queries!
    author = await user_repo.get(post.user_id)
```

## The Solution

FluxCRUD integrates the **DataLoader** pattern to batch these requests automatically.

### Usage

Use `repo.get_many_by_ids()`:

```python theme={null}
user_ids = [p.user_id for p in posts]
# 1 Query (SELECT ... WHERE id IN (...))
authors = await user_repo.get_many_by_ids(user_ids)
```

Internally, FluxCRUD collects all these IDs and fires a single optimal SQL query.
