How can I achieve a self-referencing many-to-many relationship on the SQLAlchemy ORM back referencing to the same attribute?
Here’s the UNION approach I hinted at on the mailing list earlier today. from sqlalchemy import Integer, Table, Column, ForeignKey, \ create_engine, String, select from sqlalchemy.orm import Session, relationship from sqlalchemy.ext.declarative import declarative_base Base= declarative_base() friendship = Table( ‘friendships’, Base.metadata, Column(‘friend_a_id’, Integer, ForeignKey(‘users.id’), primary_key=True), Column(‘friend_b_id’, Integer, ForeignKey(‘users.id’), primary_key=True) ) class User(Base): __tablename__ = ‘users’ id … Read more