title: SQLAlchemy: get relationships from a db.Model
body: <p>I need to get a list of a model's properties which are actually relationships (that is, they were created by <code>relationship()</code>).</p>
  
  <p>Say I have a model <code>Foo</code> in a <code>models</code>:</p>
  
  <pre><code>class Thing(db.Model):
      id = db.Column(...)
      bar_id = db.Column(...)
      foo_id = db.Column(...)
      foo = db.relationship('Foo')
      bar = db.relationship('Bar')
  </code></pre>
  
  <p>Later on, I want to take <code>models.Thing</code> and get a list of relationship-properties, that is <code>['foo', 'bar']</code>. </p>
  
  <p>Currently I'm checking every attribute indicated by <code>dir(models.Thing)</code> that happens to be of type <code>sqlalchemy.orm.attributes.InstrumentedAttribute</code> for the class of its <code>property</code> attribute — which can be either a <code>ColumnProperty</code> or <code>RelationshipProperty</code>. This does the job but I was wondering if there's another way.</p>
  
  <p>I could probably just find all attributes ending in <code>_id</code> and derive the relationship name, but this could break for some cases.</p>
  
  <p>How about setting a <code>__relationships__ = ['foo', 'bar']</code>?</p>
  
  <p>Or is there something built into SQLAlchemy to help me out?</p>