On Oct 18, 2013, at 2:49 AM, Chris <christoph.reisb...@gmail.com> wrote:
> I'm (have to) working with sqlalchemy version 0.7, > because of that I can't use .select_entity_from(). just use select_from() then, in 0.7 it does the same thing as select_entity_from(). > existing_query = session.query(TableOne).subquery() > TableOneAlias = aliased(TableOne, existing_query) > > additional_query = session.query(TableTwo).subquery() > TableTwoAlias = aliased(TableTwo, additional_query) > > combined_query = session.query(existing_query).join(additional_query) > > q = combined_query.with_entities(TableOneAlias, TableTwoAlias) > print q > print q.all() > > With this query I get the right object types as result. right there is that approach as well, sure. > Is there an other way to do this without calling aliased(...) explicitly? > For example extracting the aliased tables directly from the subquery? well it could be that query() can make this decision when it is passed another query object in certain contexts, it would act like this: def foo_thing(q): ent = q.column_descriptions[0]['expr'] return aliased(ent, q.subquery()) q1 = sess.query(A) q2 = sess.query(B) print sess.query(foo_thing(q1)).join(foo_thing(q2)).all() I've created http://www.sqlalchemy.org/trac/ticket/2847 to look into that.
signature.asc
Description: Message signed with OpenPGP using GPGMail