Skip to content

Support filtering with relation__in using model instances #1819

Open
@Abdeldjalil-H

Description

@Abdeldjalil-H

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions