Writing to linked tables in a transaction

I recently had a use case at work (a LiteStar app) where I needed to write to two linked tables (see below) in a transaction in our PostgreSQL database. In the models for the two tables was included a foreign key relationship: from sqlalchemy import Column, String, DateTime, ForeignKey from sqlalchemy.orm import Mapped, relationship from typing import List # UUIDBase automatically generates a UUID…