__tablename__ = 'general_message'
id: Mapped[int] = mapped_column(Integer, ForeignKey('announcement.id'), primary_key=True)
announcement: Mapped['Announcement'] = relationship(back_populates='general_message')
Родительская:
class Announcement(Base):
__tablename__ = 'announcement'
id: Mapped[int] = mapped_column(Integer, primary_key=True)
general_message: Mapped['GeneralMessage'] = relationship(back_populates='announcement')
При этом в экземпляре родительской модели general_message получается None.
class GeneralMessage(Announcement): __tablename__ = 'general_message' id: Mapped[int] = mapped_column(Integer, ForeignKey('announcement.id'), primary_key=True) announcement: Mapped['Announcement'] = relationship( 'Announcement', backref='general_message', primaryjoin='GeneralMessage.id == Announcement.id', foreign_keys=user_uuid, )
Обсуждают сегодня