Код: Выделить всё
class Forum(LegacyBase):
__tablename__ = "forums"
id: Mapped[int] = mapped_column("forumID", primary_key=True)
parent_id: Mapped[int] = mapped_column(
"parentID", ForeignKey("forums.forumID"), nullable=True
)
parent: Mapped["Forum"] = relationship(
"Forum", back_populates="children", remote_side="Forum.id"
)
children: Mapped[list["Forum"]] = relationship(back_populates="parent")
game_id: Mapped[int | None] = mapped_column(
"gameID", ForeignKey("games.gameID"), nullable=True
)
game: Mapped["Game"] = relationship(
"Game",
back_populates="root_forum",
primaryjoin="Forum.game_id == Game.id",
foreign_keys=[game_id],
post_update=True,
)
class Game(LegacyBase):
__tablename__ = "games"
id: Mapped[int] = mapped_column("gameID", primary_key=True)
root_forum_id: Mapped[int] = mapped_column("forumID", ForeignKey("forums.forumID"))
root_forum: Mapped["Forum"] = relationship(
"Forum",
back_populates="game",
primaryjoin="Game.root_forum_id == Forum.id",
foreign_keys=[root_forum_id],
remote_side="Forum.id",
uselist=False,
)
group_id: Mapped[int | None] = mapped_column(
"groupID", ForeignKey("forum_groups.groupID"), nullable=True
)
group: Mapped["ForumGroup"] = relationship()
Код: Выделить всё
Forum.game and back-reference Game.root_forum are both of the same direction . Did you mean to set remote_side on the many-to-one side ?
Подробнее здесь: https://stackoverflow.com/questions/798 ... two-models