🗃️ Update StopArea db models: StopArea can´t be composed of another StopAreas

This commit is contained in:
2023-04-13 21:27:07 +02:00
parent 61097fe9e2
commit 440a5faf3c

View File

@@ -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: