title: SQLAlchemy Many-to-Many Relationship on a Single Table
body: <p>I have a SQLAlchemy model set up in my application that should mimic the functionality of "followers" on Twitter, ie. users have have a many-to-many relationship with eachother (both followers and following).  The tables are structured as follows (sa is the sqlalchemy module):</p>
  
  <pre><code>t_users = sa.Table("users", meta.metadata,
      sa.Column("id", sa.types.Integer, primary_key=True),
      sa.Column("email", sa.types.String(320), unique=True, nullable=False),
      ...etc...
      )
  
  t_follows = sa.Table("follows", meta.metadata,
      sa.Column("id", sa.types.Integer, primary_key=True),
      sa.Column("follower_id", sa.types.Integer, sa.ForeignKey('users.id'), nullable=False),
      sa.Column("followee_id", sa.types.Integer, sa.ForeignKey('users.id'), nullable=False)
      )
  </code></pre>
  
  <p>I've run into a bit of a roadblock however, trying to use orm.mapper to create this relationship, since the secondary table refers back to the same primary table in both directions.  How would I go about mapping this relationship to the ORM?</p>