Make the copied columns read-only

See the following commit for another approach.
This commit is contained in:
Alexander Hess 2026-12-05 11:45:11 +01:00
commit 22286ddd0d
Signed by: alexander
GPG key ID: B46EDB4DFC26805D

View file

@ -25,11 +25,17 @@ class AddressPixelAssociation(meta.Base):
sa.Integer,
primary_key=True,
)
city_id: orm.Mapped[int] = orm.mapped_column(
# `sqlalchemy` copies it from the `.address`
# => Read-only `.city_id` below
_city_id: orm.Mapped[int] = orm.mapped_column(
"city_id",
sa.SmallInteger,
nullable=False,
)
grid_id: orm.Mapped[int] = orm.mapped_column(
# `sqlalchemy` copies it from the `.pixel`
# => Read-only `.grid_id` below
_grid_id: orm.Mapped[int] = orm.mapped_column(
"grid_id",
sa.SmallInteger,
nullable=False,
)
@ -77,3 +83,13 @@ class AddressPixelAssociation(meta.Base):
"Pixel",
back_populates="addresses",
)
# Read-only views of the private columns above
city_id: orm.Mapped[int] = orm.synonym(
"_city_id",
descriptor=property(lambda self: self._city_id),
)
grid_id: orm.Mapped[int] = orm.synonym(
"_grid_id",
descriptor=property(lambda self: self._grid_id),
)