tortoise / tortoise/tortoise-orm

I need OuterRef

Open
#1,000 3 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement
Dominant language
Python
Stars
5.6k
Forks
516
Avg merge
2d 21h
Merged PRs (30d)
9

Description

Is your feature request related to a problem? Please describe.
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

i need outerref to create prefetch & limit

Describe the solution you'd like
A clear and concise description of what you want to happen.

post_prefetch = Prefetch("posts",Post.filter(user_id=OuterRef("id")).limit(5)))
user_posts = await User.all().prefetch_related(post_prefetch)

result:

>>> user_posts[0].posts
[post 1, post 2, post 3, post 4, post 5]

Describe alternatives you've considered
A clear and concise description of any alternative solutions or features you've considered.

Additional context
Add any other context about the feature request here.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reviewing the Prefetch and prefetch_related entry points mentioned in the issue, along with how query limits are currently handled. Determine whether the requested OuterRef behavior can support a limited, per-user prefetch, and define completion as returning up to five posts for each user's relation as shown in the example.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
database
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.