Link new objects from the parent

Since SQLAlchemy 2.0, only the parent's end
cascades a new object into the session'
This commit is contained in:
Alexander Hess 2026-11-30 10:40:27 +01:00
commit ee5a372b2b
Signed by: alexander
GPG key ID: B46EDB4DFC26805D

View file

@ -74,7 +74,9 @@ class Grid(meta.Base):
Returns:
grid: including `grid.pixels` with the associated `city.addresses`
"""
grid = cls(city=city, side_length=side_length)
grid = cls(side_length=side_length)
city.grids.append(grid)
# `Pixel`s grouped by `.n_x`-`.n_y` coordinates.
pixels = {}
@ -102,7 +104,9 @@ class Grid(meta.Base):
n_x, n_y = address.x // side_length, address.y // side_length
# ... and create a new `Pixel` object if necessary.
if (n_x, n_y) not in pixels:
pixels[(n_x, n_y)] = db.Pixel(grid=grid, n_x=n_x, n_y=n_y)
pixels[(n_x, n_y)] = db.Pixel(n_x=n_x, n_y=n_y)
grid.pixels.append(pixels[(n_x, n_y)])
pixel = pixels[(n_x, n_y)]
# Create an association between the `address` and `pixel`.