I have two classes:
class Foo(SQLModel):
id: str
x: str
y: str
class Bar(SQLModel):
id: str
foo_id: str
z: str
I create a Foreign Key with Alembic migrations like this:
def upgrade():
bar_table = op.create_table(
"bars",
sa.Column("id", sa.String, nullable=False),
sa.Column("foo_id", sa.String, nullable=False),
sa.Column("foo_id", sa.String, nullable=False),
sa.PrimaryKeyConstraint("id"),
sa.ForeignKeyConstraint(
["foo_id"],
["foos.id"],
),
)
I'd like to access Foo
values inside Bar
class methods, e.g.:
class Bar(SQLModel):
id: str
foo_id: str
z: str
def process(self):
# access Foo values, e.g. `self.z = Foo.x`´
Is this possible, or should I make z
to have a FK
reference to Foo.x
?