On 10 Apr, 16:24, Joril <jor...@gmail.com> wrote:

> Now let's see if I can fetch complete instances of C instead of just
> the id X-)

For the record, my final implementation:

sub = s.query(C.d_id, func.max(C.value).label("v")).
      group_by(C.d_id).subquery()
sub2 = s.query(C).join((sub,
      and_(C.d_id==sub.c.d_id, C.value==sub.c.v))).subquery()
idmap = s.query(D.id.label("did"), sub2.c.id.label("cid")).
      outerjoin(sub2).subquery()
q = s.query(D, C).join((idmap, idmap.c.did==D.id)).
      outerjoin((C, idmap.c.cid==C.id))

Yields complete instances of D and C, having maximum C.value where
relevant :)
I must say that SQLAlchemy keeps amazing me.. Many thanks to everyone!
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to