2010-06-10 86 views
0

我知道如何獲取將從select語句返回的列,但是如何獲取將從sqlalchemy.orm.Query對象返回的實體?如何獲取SQLALchemy查詢中的實體類型

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

我想[Entity1, Entity2]或類似的東西!

回答

1

你可以試試這個:

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

雖然我不喜歡使用_entities直接屬性,並找到一些其他的方式來訪問它,但據我所知是沒有的。

相關問題