I am trying to figure out the correct join query setup within SQLAlchemy, but I can't seem to get my head around it.
I have the following table setup (simplified, I left out the non-essential fields): ```pyhton "facts_info", Base.metadata, sqlColumn("fact_id", Integer, ForeignKey("fact.id"), primary_key=True), sqlColumn("info_id", Integer, ForeignKey("info.id"), primary_key=True), class Facts(Base): __tablename__ = "facts" id = sqlColumn(Integer, primary_key=True) fact = sqlColumn(String(500), nullable=False, unique=True) created_at = sqlColumn(DateTime) updated_at = sqlColumn(DateTime) # Relationships info = relationship("Info", secondary=sachverhalt_info, back_populates="fact") class Info(Base): __tablename__ = "info" id = sqlColumn(Integer, primary_key=True) filename = sqlColumn(String(50)) format = sqlColumn(String(10)) # Relationships fact = relationship("Facts", secondary=facts_info; back_populates="info") text = relationship("Text", secondary=facts_info; back_populates="info") "info_text", Base.metadata, sqlColumn("info_id", Integer, ForeignKey("info.id"), primary_key=True), sqlColumn("text_id", Integer, ForeignKey("text.id"), primary_key=True) class Text(Base): __tablename__ = "text" id = sqlColumn(Integer, primary_key=True) text = sqlColumn(String(1000)) # Relationships info = relationship("Info", secondary=info_text; back_populates="text") ``` The facts are associated to info, info is associated to text. Text and facts aren't directly associated. I would like to join them all together but can't figure out to do so. In this example I would like to get all instaces of "Info" that are associated to Fact.id = 1 and all "Text" instances that are associated to that "Info" instance. I came up with ```python select(Info, Text).join(facts_info).join(Facts).join(info_text).join(Text).where(Facts.id ==1) ``` But it obviously gives me an error. -- SQLAlchemy - The Python SQL Toolkit and Object Relational Mapper http://www.sqlalchemy.org/ To post example code, please provide an MCVE: Minimal, Complete, and Verifiable Example. See http://stackoverflow.com/help/mcve for a full description. --- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To unsubscribe from this group and stop receiving emails from it, send an email to sqlalchemy+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/sqlalchemy/9c62e7f4-ec8f-4f96-b122-251db6a2a9efn%40googlegroups.com.