Make the copied columns read-only
See the following commit for another approach.
This commit is contained in:
parent
c5be06fb57
commit
22286ddd0d
1 changed files with 18 additions and 2 deletions
|
|
@ -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),
|
||||
)
|
||||
|
|
|
|||
Loading…
Reference in a new issue