title: Flask SQLAlchemy relationship
body: <p>I have a pretty simple model in Flask and SQLAlchemy, with companies playing matches. A match is defined by a host and a guest. I don't know how to bring the host and the guest companies to the template, I am getting their IDs.</p>
  
  <p>The code is like this:</p>
  
  <pre><code>class Company(db.Model):
  
      __tablename__ = 'companies'
      id = db.Column(db.Integer, primary_key = True)
      name = db.Column(db.String(64), unique = True)
      address = db.Column(db.String(120), unique = False)
      website = db.Column(db.String(100), unique = False)
      ...
  
  class Match(db.Model):
  
      __tablename__ = 'matches'
      id = db.Column(db.Integer, primary_key = True)
  
      local_id =db.Column(db.Integer, db.ForeignKey('companies.id'))    
      guest_id = db.Column(db.Integer, db.ForeignKey('companies.id'))
  
      match_time = db.Column(db.DateTime())   # not important
  </code></pre>
  
  <p>I would like to be able to do something like this in the template:</p>
  
  <pre><code>{{ match.host.name }} - {{ match.guest.name }}
  </code></pre>
  
  <p>Any help would be greatly appreciated.</p>