Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support filtering with relation__in using model instances #1819

Open
Abdeldjalil-H opened this issue Dec 19, 2024 · 0 comments
Open

Support filtering with relation__in using model instances #1819

Abdeldjalil-H opened this issue Dec 19, 2024 · 0 comments
Labels
enhancement New feature or request

Comments

@Abdeldjalil-H
Copy link
Contributor

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.

@henadzit henadzit added the enhancement New feature or request label Dec 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants