title: How do I return columns from different table using SQLAlchemy, Flask?
body: <p>I am trying to use SQLAlchemy, Marshmallow and FLask to query the tables from my classes Submission_status, Policy. I am trying to create a route call summary.py to use GET request to fetch something like this for my frontend:</p>
  <pre><code>&quot;policy_id&quot;: &quot;X0002&quot;,
  &quot;policy_holder&quot;: &quot;Mr Bean&quot;,
  &quot;policy_holder_contact&quot;:&quot;0123456789&quot;
  &quot;policy_holder_email&quot;:&quot;bean@hotmail.com&quot;
  &quot;product_id&quot;:&quot;1&quot;,
  &quot;status&quot;: &quot;incomplete&quot;,
  &quot;description&quot;:&quot;Pending UW&quot;,
  &quot;days_in_current_status&quot;:&quot;3&quot;,
  &quot;sales_name&quot;:&quot;Ali&quot;,
  &quot;sales_contact&quot;:&quot;0123454666&quot;,
  &quot;sales_email&quot;:&quot;ali@message.com&quot;,
  &quot;submission_date&quot;:&quot;12/12/2022
  </code></pre>
  <p>I would like to get these datas from the following table:</p>
  <pre><code>  'policy_id': Submission_status.policy_id,
    'policy_holder':Policy.policy_holder,
    'policy_holder_contact':Policy.policy_holder_contact,
    'policy_holder_email':Policy.policy_holder_email,
    'product_id':Policy.product_id,
    'status':Submission_status.status,
    'description':Submission_status.description,
    'num_days':(func.age(datetime.utcnow().strftime('%B %d %Y'),Submission_status.status_date)/86400).label('days'),
    'sales_name':Policy.sales_name,
    'sales_contact':Policy.sales_contact,
    'sales_email':Policy.sales_email,
    'submission_date':Submission_status.status_date
  </code></pre>
  <p>My Models and Schemas are as shown below:</p>
  <pre><code>''models.py''
  
  #Policy Model
  class Policy(db.Model):
      id = db.Column(db.Integer, primary_key=True)
      sub_date = db.Column(db.DateTime, nullable=False, default=datetime.utcnow)
      product_id=db.Column(db.Integer, db.ForeignKey('product.id'), nullable=False)
      policy_holder=db.Column(db.String(50),nullable=False)
      policy_holder_contact=db.Column(db.String(50))
      policy_holder_email=db.Column(db.String(50))
      sales_name=db.Column(db.String(50))
      sales_contact=db.Column(db.String(50))
      sales_email=db.Column(db.String(50))
      sales_date=db.Column(db.DateTime)
    
      def __init__ (self,sub_date,product_id,policy_holder,policy_holder_contact,policy_holder_email,sales_name,sales_contact,sales_email,sales_date):
          self.sub_date=sub_date
          self.product_id=product_id
          self.policy_holder=policy_holder
          self.policy_holder_contact=policy_holder_contact
          self.policy_holder_email=policy_holder_email
          self.sales_name=sales_name
          self.sales_contact=sales_contact
          self.sales_email=sales_email
          self.sales_date=sales_date
  
  #Policy schema
  class PolicySchema(ma.Schema):
      class Meta:
          fields=('id','sub_date','product_id','policy_holder','policy_holder_contact','policy_holder_email','sales_name','sales_contact','sales_email','sales_date')
  
  
  policy_schema=PolicySchema()
  policys_schema=PolicySchema(many=True)    
  
  
  #Submission_status Model
      class Submission_status(db.Model):
          id=db.Column(db.Integer,primary_key=True)
      status_date=db.Column(db.DateTime,nullable=False,default=datetime.utcnow)
    policy_id=db.Column(db.Integer,db.ForeignKey('policy.id'),nullable=False)
      policy = db.relationship('Policy', backref='submission_status')
      description=db.Column(db.String(200))
      status=db.Column(db.String(50),nullable=False)
      user_id=db.Column(db.Integer,db.ForeignKey('user.id'),nullable=False)
      def __init__ (self,status_date,policy_id,description,status,user_id):
          self.status_date=status_date
          self.policy_id=policy_id
          self.description=description
          self.status=status
          self.user_id=user_id
  
  class SubmissionStatusSchema(ma.Schema):
      class Meta:
          fields=('id','status_date','policy_id','description','status','user_id','user.name','days')
  
  submissionstatus_schema=SubmissionStatusSchema()
  submissionstatuss_schema=SubmissionStatusSchema(many=True)  
  
  #Summary Schema
  class SummarySchema(ma.Schema):
      class Meta:
          fields = ('submission_status.policy_id'
                    'policy.policy_holder',
                    'policy.policy_holder_contact',
                    'policy.policy_holder_email',
                    'policy.product_id',
                    'submission_status.status',
                    'submission_status.description',
                    'policy.sales_name',
                    'policy.sales_contact',
                    'policy.sales_email',
                    'submission_status.status_date,',
                    )
  summary_schema = SummarySchema()
  summarys_schema = SummarySchema(many=True)
  </code></pre>
  <p>Don't mind the wrong indentation, It is indented in the project and works fine for other functions.</p>
  <p>And here is my code in summary.py:</p>
  <pre><code>@summary.route(&quot;/&quot;, methods = ['GET'])
  def get_summary():
          summary = db.session.query(Submission_status, Policy).outerjoin(Submission_status,Policy.id == Submission_status.policy_id).all()
          result = submissionstatuss_schema.dump(summary)
          
          return jsonify(result)
  </code></pre>
  <p>Can anyone help me on this? I keep getting empty brackets when I run the server and on the web...</p>