🚑️ /stop responses didn't return StopArea.stops fields

This commit is contained in:
2023-05-07 12:36:38 +02:00
parent c6e3881966
commit c84b78d3e2

View File

@@ -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()