title: How to change parent using relations in sqlalchemy?
body: <p>Here is the simple example of relationship with backref and delete cascade.</p>
  
  <pre class="lang-python prettyprint-override"><code>class Parent(Base):
      __tablename__ = 'parent'
      id = Column(Integer, primary_key=True)
  
  class Child(Base):
      __tablename__ = 'child'
      id = Column(Integer, primary_key=True)
      parent_id = Column(Integer, ForeignKey('Parent.id'))
      parent = relation(
          'Parent',
          backref=backref('children', cascade='delete, delete-orphan')
      )
  </code></pre>
  
  <p>Need to reassign some children from one parent to another, then need to delete another parent, but sqlalchemy deletes children before parent removal...</p>
  
  <pre class="lang-python prettyprint-override"><code>p1 = Session.query(Parent).get(...)
  p2 = Session.query(Parent).get(...)
  
  p1.children.extend(p2.children)
  Session.delete(p2)
  Session.commit()
  </code></pre>
  
  <p>Log:</p>
  
  <pre><code>... [worker 0] UPDATE child SET parent_id=%(parent_id)s WHERE child.id = %(child_id)s
  ...
  ... [worker 0] DELETE FROM child WHERE child.id = %(id)s
  ...
  ... [worker 0] DELETE FROM parent WHERE parent.id = %(id)s
  ...
  ... [worker 0] COMMIT
  </code></pre>
  
  <p>Need to somehow detach children from another parent...</p>