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:
parent
87aaebe475
commit
ee5a372b2b
1 changed files with 21 additions and 6 deletions
|
|
@ -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`.
|
||||
|
|
|
|||
Loading…
Reference in a new issue