tortoise / tortoise/tortoise-orm
Support filtering with `relation__in` using model instances
Nobody has claimed this yet.
- 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.
In Django ORM, we can efficiently filter related objects using relation__in syntax, for example
Post.objects.filter(author__in=[user1, user2])
However, Tortoise ORM only supports relation_id__in, requiring us to extract IDs manually before filtering. This makes queries more verbose and less intuitive, especially when working with object instances rather than IDs.
Describe the solution you'd like
Add support for relation__in filtering in Tortoise ORM, allowing direct filtering using model instances similar to Django's implementation. For example:
await Post.filter(author__in=[user1, user2]) # Currently not supported
# Instead of current approach:
await Post.filter(author_id__in=[user1.id, user2.id])
Additional context
This feature would improve compatibility with Django ORM patterns.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at the Post.filter entry point and trace how the existing relation_id__in syntax is handled. Compare the desired relation__in examples with current filtering behavior, then add coverage showing that model instances can be passed directly and that existing ID-based filtering remains supported.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- database
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100