title: How to delete a one-to-one relationship with SQLAlchemy
body: <p>I would like to create a nullable, self-referencing relationship which can be deleted using SQLAlchemy. An example model is as follows (note, using Flask-SQLAlchemy):</p>
  
  <pre><code>class Person(db.Model):
  
      __tablename__ = 'person'
  
      id          = db.Column(db.Integer, primary_key=True)
      partner_id  = db.Column(db.Integer, db.ForeignKey('person.id'), nullable=True)
      partner     = db.relationship('Person', uselist=False)
  </code></pre>
  
  <p>So think of this as a table of cops who have only a single partner, but that partner may turn out to have been in the mafia all along, so they lose their partner for a while. A cop without a partner is fine, at least in database terms - but I assume over the course of the show their partnerless status means a lot of property damage. </p>
  
  <p>Needless to say, this question: <a href="https://stackoverflow.com/questions/3464443/sqlalchemy-one-to-one-relationship-with-declarative/9611874#9611874">sqlalchemy: one-to-one relationship with declarative</a> discusses how to set up this relationship. The question is how do you remove the relationship? Normally with a different foreign key you'd do this as follows:</p>
  
  <pre><code>joe.partner.remove(larry)
  </code></pre>
  
  <p>Where <code>joe</code> and <code>larry</code> are both <code>Person</code> objects. However, via the <code>uselist</code> argument, <code>joe.partner</code> is now actually a <code>Person</code> with no <code>remove</code> method. </p>