-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Labels
Description
Summary
Support eager loading of relationships to avoid N+1 query patterns. Users should be able to prefetch related models in a single (or batched) query instead of loading relations one-by-one when iterating.
Current state
Status: Not implemented.
Documentation references:
docs/coming-soon.md(Eager Loading / Prefetch Related)docs/guide/queries.md(lines 211-214, 318-321)
Current workaround: Manually load relationships as needed; be mindful of N+1 patterns.
Proposed API (example)
# This does not work yet
posts = await Post.select().prefetch_related("author").all()- Query builder would gain something like
.prefetch_related("author")(and possibly multiple relations, e.g..prefetch_related("author", "comments")). - Resulting instances would have the requested relations already loaded (e.g.
post.authorusable without an extra query).
Acceptance criteria
- Query API supports prefetching one or more relation names (e.g.
prefetch_related("author")orprefetch_related("author", "comments")). - Prefetched relations are loaded efficiently (batched / minimal queries), not per-row.
- Accessing a prefetched relation on a model instance does not trigger an additional query.
- Docs updated: remove from Coming Soon and document in the queries guide; update any performance/concepts docs that reference prefetch.
Reactions are currently unavailable