title: Self Referential Relationship in SQLAlchemy
body: <p>I am trying to create a self referential relationship in SQLAlchemy.</p>
  
  <p>I have a class 'Issue' that may have identical 'Issue' siblings that are exactly the same but have a different cover image attribute.</p>
  
  <p>I would like each model to contain an attribute containing a list of its siblings but not itself if possible.</p>
  
  <p>My issue model currently looks like this:</p>
  
  <pre><code>class Issue(db.Model):
      __tablename__ = 'issues'
      # IDs
      id = db.Column(db.Integer, primary_key=True)
      title_id = db.Column(db.Integer, db.ForeignKey('titles.id'))
      publisher_id = db.Column(db.Integer, db.ForeignKey('publishers.id'))
      parent_id = db.Column(db.Integer, db.ForeignKey('issues.id'))
      # Attributes
      product_id = db.Column(db.String(100))
      issue_number = db.Column(db.Float)
      .......
      # Relationships
      is_parent = db.Column(db.Boolean(), default=False)
      alternates = db.relationship('Issue',
                  backref=db.backref('parent', remote_side=[id])
              )
  </code></pre>
  
  <p>Each Issue has an 'is_parent' attribute that I set when it is determined that the issue is the 'base' issue. However, I still want all siblings to be able to access one another.</p>
  
  <p>Currently, I am giving the 'parent' issue a relationship with all of its 'children'/'siblings'. </p>
  
  <p>The problem occurs when I am interacting with an instance of a 'sibling'. I would like to directly access all of its relatives but I must go through the parent first.</p>
  
  <p>Any help would be greatly appreciated!</p>
  
  <p>EDIT: Basically, I would like to create a self-referential many-to-many relationship. Am I wrong in believing this is the correct direction to pursue?</p>