title: Flask, Join two models with foreign key
body: <p>my two models are </p>
  
  <pre><code>class Users (db.Model):
      UserId = db.Column(db.INTEGER, primary_key=True,autoincrement=True)
      UserName = db.Column(db.String(25),nullable=False, unique=True)
      Email = db.Column(db.String,nullable=False,unique=True)
      plan = db.relationship(
          'Messages',
          collection_class=attribute_mapped_collection('language'),
          cascade="all,delete"
      )
  
  class Messages (db.Model):
      MessageId = db.Column(db.INTEGER,primary_key=True,autoincrement=True)
      SenderId = db.Column(db.INTEGER,db.ForeignKey('Users.UserId'),nullable=False)
      language = db.Column(db.Enum('de', 'en'), nullable=False)
  </code></pre>
  
  <p>Now, My view looks like:</p>
  
  <pre><code>def premium():
      usr_obj = models.Users.query.join(models.Messages)\
          .order_by(models.Users.UserId.desc())
  
      return render_template('user_plan.html', user=usr_obj)
  </code></pre>
  
  <p>My user_html is like:</p>
  
  <pre><code>{% for a in user %}
              {{ a.UserName }} &lt;/br&gt; {{ a.SenderID }} &lt;/br&gt;
          {% endfor %}
  </code></pre>
  
  <p>It is giving me only value of {{ a.UserName }} and not of {{ a.SenderID }}, why??</p>