Skip to content

Query OR conditional between multiple field #117

Closed
@Justinianus2001

Description

@Justinianus2001

I have a table called 'Client' as shown below:

class Client(Base):
    __tablename__ = "client"

    id: Mapped[int] = mapped_column("id", autoincrement=True, nullable=False, unique=True, primary_key=True, init=False)

    name: Mapped[str] = mapped_column(String(50))
    contact: Mapped[str] = mapped_column(String(50))
    phone: Mapped[str] = mapped_column(String(20))
    email: Mapped[str] = mapped_column(String(50))

I want to perform a search across all fields in this table using the parameter 'keyword', for example:

name__ilike = f'%{keyword}%' OR contact__ilike = f'%{keyword}%' OR phone__ilike = f'%{keyword}%' OR email__ilike = f'%{keyword}%'

In my research of the documentation, I only found a way to query an OR condition within a single field, such as price__or={'lt': 5, 'gt': 20}. Please help me find a solution. Thank you very much!

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