I'm sorry, I totally misunderstood your question. I thought you were trying 
to get all rows as a unified dict.  Your result clarified things.

It looks like you're using the ORM (and not core), right?

I don't think it is entirely possible to do what you want.  Several people 
have asked similar questions in the past...  you essentially want 
SqlAlchemy to return somewhat raw data.

The problem isn't with the `join`, it's with the `query`.  

This bit:

    query(table1.t1c2, table2)

Is instructing SqlAlchemy to return a tuple that contains those two 
discrete "objects" - the first being a column of `table1`, the second being 
a instance of `table2` (or a row).  The ORM is then mapping table2 onto an 
object.

To *somewhat* achieve your goal and avoid the object creation, you can 
explicitly enumerate your query:

    r = db.session.query(Table1.t1c2, Table2.t2c1, Table2.t2c2, 
Table2.t2c3).join(Table2).all()

That will return an iterator of 3 element tuples in that order:

    [(u'one', 11, u'qwe', 1),
     (u'two', 22, u'rty', 2),
     (u'one', 33, u'zxcvb', 1)
     ]

You can cast each one into a dict individually:

    for row in r:
       print row._as_dict()

will generate:

    {'t1c2': u'one', 't2c3': 1, 't2c2': u'qwe', 't2c1': 11}
    {'t1c2': u'two', 't2c3': 2, 't2c2': u'rty', 't2c1': 22}
    {'t1c2': u'one', 't2c3': 1, 't2c2': u'zxcvb', 't2c1': 33}

That brings me to this point -- can you share a self-contained example of 
your code?

I can't figure out how you're getting `q.all()._asdict()` to work.  It 
shouldn't work, because the result should be an iterable/list that does not 
have that method.

-- 
SQLAlchemy - 
The Python SQL Toolkit and Object Relational Mapper

http://www.sqlalchemy.org/

To post example code, please provide an MCVE: Minimal, Complete, and Verifiable 
Example.  See  http://stackoverflow.com/help/mcve for a full description.
--- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

Reply via email to