views:

34

answers:

1

I know how to get the columns that would be returned from a select statement but how do I get the entities that would be returned from an sqlalchemy.orm.Query object?

>>> sess = Session()
>>> q = sess.query(Entity1, Entity2)
>>> q.statement.c.keys()
['e1_col1', 'e1_col2', ..., 'e2_col1', 'e2_col2, ...]

I want [Entity1, Entity2] or something similar!

A: 

You can try this:

[e.mapper.class_ for e in q._entities]

Although I would prefer not to use _entities attribute directly and find some other way to access it, but AFAIK there is none.

zifot