I have the following tables configured:
class User(Base): __tablename__ = "user" id = Column(Integer, primary_key=True) name = Column(String) class Gadget(Base): __tablename__ = "gadget" id = Column(Integer, primary_key=True) brand = Column(String) class UserGadget(Base): __tablename__ = "user_gadget" user_id = Column(Integer, ForeignKey('user.id'), primary_key=True) gadget_id = Column(Integer, ForeignKey('gadget.id'), primary_key=True) user = relationship("User", backref=backref('userGadgets', order_by=user_id)) gadget = relationship("Gadget", backref=backref('userGadgets', order_by=gadget_id)) class GadgetComponent(Base): __tablename__ = "gadget_component" id = Column(String, primary_key=True) gadget_id = Column(Integer,ForeignKey('gadget.id')) component_maker = Column(String) host = relationship("Gadget", backref=backref('components', order_by=id)) class ComponentUsingMetal(Base): __tablename__ = "component_metal" id = Column(Integer, primary_key=True) component_id = Column(Integer, ForeignKey('GadgetComponent.id')) metal = Column(String) component = relationship("GadgetComponent", backref=backref('gadgetComponentMetals', order_by=id)) On doing the following query: session.query(User).join("userGadgets", "gadget", "components","gadgetComponentMetals").filter(ComponentUsingMetal.metal == 'iron') , component_metal gets attached to the query twice giving an error 'table name component_metal specified more than once'.
Any idea what I am doing wrong?