From c84b78d3e274d0423d20aa0a0990ba57c6c083f9 Mon Sep 17 00:00:00 2001 From: Adrien Date: Sun, 7 May 2023 12:36:38 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=9A=91=EF=B8=8F=20/stop=20responses=20did?= =?UTF-8?q?n't=20return=20StopArea.stops=20fields?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/backend/models/stop.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/backend/backend/models/stop.py b/backend/backend/models/stop.py index 49c0f30..dd7b87c 100644 --- a/backend/backend/models/stop.py +++ b/backend/backend/models/stop.py @@ -23,6 +23,7 @@ from sqlalchemy.orm import ( Mapped, relationship, selectinload, + with_polymorphic, ) from sqlalchemy.schema import Index from sqlalchemy_utils.types.ts_vector import TSVectorType @@ -98,11 +99,17 @@ class _Stop(Base): if (session := await cls.db.get_session()) is not None: async with session.begin(): - match_stmt = cls.names_tsv.match(name, postgresql_regconfig="french") - ranking_stmt = func.ts_rank_cd( - cls.names_tsv, func.plainto_tsquery("french", name) + descendants = with_polymorphic(_Stop, "*") + + match_stmt = descendants.names_tsv.match( + name, postgresql_regconfig="french" + ) + ranking_stmt = func.ts_rank_cd( + descendants.names_tsv, func.plainto_tsquery("french", name) + ) + stmt = ( + select(descendants).filter(match_stmt).order_by(desc(ranking_stmt)) ) - stmt = select(cls).filter(match_stmt).order_by(desc(ranking_stmt)) res = await session.execute(stmt) stops = res.scalars().all()