Код: Выделить всё
class A(SQLModel, table=True):
id: int | None = Field(default=None, primary_key=True)
b_id: int | None = Field(default=None, foreign_key="b.id")
b: 'B' = Relationship(back_populates='as')
c: 'C' = Relationship() # Somehow have this automatically populated through b.c_id?
class B(SQLModel, table=True):
id: id | None = Field(default=None, primary_key=True)
c_id: int | None = Field(default=None, foreign_key='c.id)
as: list[A] = Relationship(back_populates='b')
c: 'C' = Relationship(back_populates='bs')
class C(SQLModel, table=True):
id: int | None = Field(default=None, primary_key=True)
bs: list[B] = Relationship(back_populates='c')
Подробнее здесь: https://stackoverflow.com/questions/787 ... reign-keys
Мобильная версия