Nevermind.  I kept digging and found Query.correlate().  This code
works:

        Session.query(TableC.id, TableC.group_key)
        .join(TableC.b, TableB.a)
        .filter(TableA.some_key == 42)
        .filter(TableC.sort_key ==
                Session.query(func.max(c1.sort_key))
                .join(b1)
                .filter(c1.group_key == TableC.group_key)
                .filter(b1.a_id == TableA.id)
                .correlate(TableC, TableA)
                .as_scalar())

The correlate() method does not seem to be particularly well-
documented.  I had read somewhere that SQLAlchemy auto-correlates, but
apparently not in this case.  Should there be a correlated subquery
example in the tutorials, maybe?  When does and doesn't SA
automatically correlate subqueries?

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.

Reply via email to