[Sqlalchemy-tickets] Issue #3320: Query.with_entities don't "copy" query options (zzzeek/sqlalchemy
Brought to you by:
zzzeek
|
From: Hugo B. <iss...@bi...> - 2015-03-11 13:09:48
|
New issue 3320: Query.with_entities don't "copy" query options https://bitbucket.org/zzzeek/sqlalchemy/issue/3320/querywith_entities-dont-copy-query-options Hugo Braquinho: I'm doing some pagination and trying to count the number of results ``` #!python query = session.query(Group.id) print query # SELECT groups.id AS groups_id FROM groups print query.with_entities(func.count(1)) # SELECT count(:param_1) AS count_1 ``` The count query don't have any FROM, i understand why this happen, but there is no way to preserve query froms? I can fix this adding all entities ``` #!python query = session.query(Group.id) print query # SELECT groups.id AS groups_id FROM groups print query.with_entities(func.count(1), *[e.expr for e in query._entities]) # SELECT count(:param_1) AS count_1, iduc_groups.id AS iduc_groups_id FROM iduc_groups ``` But i don't know if it works for every defined entities |