Using postgresql with sqlalchemy, I want to let a child know when a value in parent table has been updated:
class Parent(Base):
__tablename__ = "parent_table"
id = mapped_column(Integer, primary_key=True)
children = relationship("Child", cascade = "all,delete", back_populates="parent")
some_val = mapped_column(Integer)
class Child(Base):
__tablename__ = "child_table"
id = mapped_column(Integer, primary_key=True)
parent_id = mapped_column(ForeignKey("parent_table.id"))
parent = relationship("Parent", back_populates="children")
some_val_modified = mapped_column(Boolean)
In the above scenario, I want some_val_modified
to be set to true whenever some_val
has been modified in the parent class. Is there a way I can do that?
I was trying to make a function that achieves this using onupdate
, but couldn't figure out the proper syntax or if this is even allowed using documentation.