From 440a5faf3c426284633979515290dc3be2130349 Mon Sep 17 00:00:00 2001 From: Adrien Date: Thu, 13 Apr 2023 21:27:07 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=97=83=EF=B8=8F=20Update=20StopArea=20db?= =?UTF-8?q?=20models:=20StopArea=20can=C2=B4t=20be=20composed=20of=20anoth?= =?UTF-8?q?er=20StopAreas?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/backend/models/stop.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/backend/backend/models/stop.py b/backend/backend/models/stop.py index f75e1ea..d286878 100644 --- a/backend/backend/models/stop.py +++ b/backend/backend/models/stop.py @@ -130,12 +130,12 @@ class StopArea(_Stop): id = mapped_column(BigInteger, ForeignKey("_stops.id"), primary_key=True) type = mapped_column(Enum(StopAreaType), nullable=False) - stops: Mapped[list["_Stop"]] = relationship( - "_Stop", + + stops: Mapped[list["Stop"]] = relationship( + "Stop", secondary=stop_area_stop_association_table, back_populates="areas", lazy="selectin", - # lazy="joined", ) __tablename__ = "stop_areas" @@ -157,17 +157,17 @@ class StopArea(_Stop): stop_area_ids.add(stop_area_id) stop_ids.add(stop_id) - stop_areas_res = await session.execute( + stop_areas_res = await session.scalars( select(StopArea) .where(StopArea.id.in_(stop_area_ids)) .options(selectinload(StopArea.stops)) ) stop_areas: dict[int, StopArea] = { - stop_area.id: stop_area for stop_area in stop_areas_res.scalars() + stop_area.id: stop_area for stop_area in stop_areas_res.all() } - stop_res = await session.execute(select(_Stop).where(_Stop.id.in_(stop_ids))) - stops: dict[int, _Stop] = {stop.id: stop for stop in stop_res.scalars()} + stop_res = await session.execute(select(Stop).where(Stop.id.in_(stop_ids))) + stops: dict[int, Stop] = {stop.id: stop for stop in stop_res.scalars()} found = 0 for stop_area_id, stop_id in stop_area_to_stop_ids: