actually, you'd be constraining the join against the edge elements since the base is a node. (edge is the more common name for your usage/link)
if you're searching for node2, then you'd constrain the query by joining the edge items like this: result = session.query(node_2)\ .join(edge_1, node_2.id == edge_1.second_id)\ .join(edge_2, node_2.id == edge_2.first_id)\ you don't have a `relationship` on the Node table, so you can define that on the edge via `backref` kwarg (http://docs.sqlalchemy.org/en/latest/orm/relationship_api.html#sqlalchemy.orm.relationship.params.backref) or create symmetric relationships on edge and node and reference one another with the `back_populates` kwarg (http://docs.sqlalchemy.org/en/latest/orm/relationship_api.html#sqlalchemy.orm.relationship.params.back_populates). Once you have those relationships defined, you can just eagerload node1 and node3 off the edge_1 and edge_2 objects respectively (that's covered in the backref tutorial, there's a link to it in the backref docs above). efficiency depends on your database, dataset, database indexes and what your queries are expected to do. -- 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.