title: How do I return results from both tables in a SQLAlchemy JOIN?
body: <p>I have two tables defined in my ORM as:</p>
  
  <pre><code>Base = declarative_base()
  
  class GeneralLedger(Base):
    __tablename__ = 'generalledgers'
    id = Column(Integer, primary_key=True)
    invoiceId = Column(Integer)
    ..
  
  class ConsolidatedLedger(Base):
    __tablename__ = 'consolidatedledgers'
    id = Column(Integer, primary_key = True)
    invoiceId = Column(Integer)
  </code></pre>
  
  <p>..</p>
  
  <p>I don't have any relationship set between the two tables. I do a join as follows:</p>
  
  <pre><code>records = DBSession.query(GeneralLedger).join(ConsolidatedLedger, GeneralLedger.invoiceId == ConsolidatedLedger.invoiceId).all()
  </code></pre>
  
  <p>I've also tried:</p>
  
  <pre><code>records = DBSession.query(GeneralLedger).filter(GeneralLedger.invoiceId == ConsolidatedLedger.invoiceId).all()
  </code></pre>
  
  <p>In both cases, when I display the results in my view, only the entries from the GeneralLedger table show up. How do I get results from both tables in the same result set? I've tried this:</p>
  
  <pre><code>records = DBSession.query(GeneralLedger, ConsolidatedLedger).join(ConsolidatedLedger, GeneralLedger.invoiceId == ConsolidatedLedger.invoiceId).all()
  </code></pre>
  
  <p>But, for some reason, when I iterate through the results in my template (Jinja2), the values for the columns are empty for every single row. Also, when count:</p>
  
  <pre><code>total = DBSession.query(GeneralLedger).join(ConsolidatedLedger, GeneralLedger.invoiceId == ConsolidatedLedger.invoiceId).count()
  </code></pre>
  
  <p>The total rows is the sum of the matching records from the two tables. I'm using webhelpers.paginate to handling paging:</p>
  
  <pre><code>query = DBSession.query(GeneralLedger).join(ConsolidatedLedger, GeneralLedger.invoiceId == ConsolidatedLedger.invoiceId)
  records = paginate.Page(query, current_page, url=page_url)
  </code></pre>
  
  <p>and the result set sent to the template is as if all the results where there but the ones on the ConslidatedLedger table are removed. For example, I have my page total set to 20 records. If there are records from ConslidatedLedger on that page, the page is truncated, only showing records from GeneralLedger but the paging isn't broken.</p>
  
  <p>Any thoughts? Thanks!</p>