title: SQLAlchemy Join to retrieve data from multiple tables
body: <p>I'm trying to retrieve data from multiple tables with <strong>SQLAlchemy</strong> using the <strong>.join()</strong> method.  </p>
  
  <p>When I run the query I was expecting to get a single object back which had all the data from the different tables joined so that I could use <strong>a.area_name</strong> and so on where <strong>area_name</strong> is on one of the joined tables.  Below is the query I am running and the table layout, if anyone could offer insight into how to achieve the behavior I'm aiming for I would greatly appreciate it!  I've been able to use the <strong>.join()</strong> method with this same syntax to match results and return them, I figured it would return the extra data from the rows as well since it <strong>joins</strong> the tables (perhaps I'm misunderstanding how the method works or how to retrieve the information via the query object?).</p>
  
  <p>If it helps with the troubleshooting I'm using MySQL as the database</p>
  
  <p>query:</p>
  
  <pre><code>a = User.query.filter(User.user_id==1).join(UserGroup,
   User.usergroup==UserGroup.group_id).join(Areas, User.area==Areas.area_id).first()
  </code></pre>
  
  <p>and the tables:</p>
  
  <pre><code>class User(db.Model):
      user_id = db.Column(db.Integer, primary_key=True)
      name = db.Column(db.String(20), unique=True)
      usergroup = db.Column(db.Integer, db.ForeignKey('user_group.group_id'), nullable=False)
      area = db.Column(db.Integer, db.ForeignKey('areas.area_id'), nullable=False)
  
  class UserGroups(db.Model):
      id = db.Column(db.Integer, primary_key=True)
      group_id = db.Column(db.Integer, nullable=False, unique=True)
      group_name = db.Column(db.String(64), nullable=False, unique=True)
  
  
  class Areas(db.Model):
      id = db.Column(db.Integer, primary_key=True)
      area_id = db.Column(db.Integer, nullable=False, unique=True)
      area_name = db.Column(db.String(64), nullable=False, unique=True)
  </code></pre>