Hi Mike, I am creating a graph structure using the ORM below and am able to do inserts.
Base = declarative_base() class Link(Base): __tablename__ = 'base_link' _constraints = ['first_id', 'second_id'] __table_args__ = (UniqueConstraint(*_constraints, name = 'link_constraint'), {"schema":"my_schema"}) id = Column(CHAR(32), primary_key=True) object_type = Column(String(16)) first_id = Column(CHAR(32), ForeignKey(Node.id)) second_id = Column(CHAR(32), ForeignKey(Node.id)) orl1 =relationship('Node', foreign_keys=first_id) orl2 =relationship('Node', foreign_keys=second_id) class Node(Base): __tablename__ = 'node' _constraints = ['h_name', 'd_name'] __table_args__ = (UniqueConstraint(*_constraints, name='node_constraint'), {"schema":"my_schema"}) h_name = Column(String(256),nullable=False) d_name = Column(String(256),nullable=True) id = Column(CHAR(32),primary_key=True) I am having a hard time querying the above Objects for example: Case-1 (ref case-1.png): my join was pretty much straightforward for Case-1. Usage = aliased(Link, name = "Usage") node_1 = aliased(Node, name = "node_1") node_2 = aliased(Node, name = "node_2") session.query(node_1, node_2).join(Usage, node_1.id == Usage.first_id).join(node_2, node_2.id == Usage.second_id) How would my join be for my Case-2 (ref case-2.png)? Usage = aliased(Link, name = "Usage") Usage_2 = aliased(Link, name = "Usage_2") node_1 = aliased(Node, name = "node_1") node_2 = aliased(Node, name = "node_2") node_3 = aliased(Node, name = "node_3") I cannot quite properly build the query the query below is as close as I can get session.query(node_1, node_2, node_3).join(Usage, node_1.id==Usage.first_id).join(Usage_2, node_3.id==Usage_2.first_id).join(node_2, and_(node_2.id==Usage.second_id, node_2.id==Usage_2.second_id)) which I know is wrong. It will be really nice if someone could point me in the right direction for my case-2 join. Regards, Madhusudan Sridharan -- 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 post to this group, send email to sqlalchemy@googlegroups.com. Visit this group at https://groups.google.com/group/sqlalchemy. For more options, visit https://groups.google.com/d/optout.