> My problem is: I want to be able to select from Thread, ordering it > by descending order of the maximum tn_ctime for each thread, to > find the most recently referenced threads. Which is to say, I want > to do something like > > select > t.*, > coalesce(c.most_recent_child, t.tn_ctime) as last_upd > from tnode t > left join (select tn_parent as node_id, max(tn_ctime) as > most_recent_child from tnode group by tn_parent) c on > c.node_id==t.tn_id group by t.tn_id > order by last_upd desc; > > Is it possible to add a property to Thread holding the maximum > child node timestamp if any (or the thread node's timestamp, if > none), so that I can do something like > > Thread.select(Thread.c.tn_parent==forum_id, > order_by=desc(Thread.c.last_upd)) > > ? >
i dont think i got what u want from these examples, but adding a property that always fires a select is easy: class Thread: ... @property def mymaxprop( self): return self.select(...) or whatever eventualy u can put some cache, but you're responsible for keeping it uptodate Another way would be to play with relation, maybe it can do something like that too; And another way is to look here: http://www.mr-pc.kiev.ua/en/projects/SQLAlchemyAggregator/ or another ~copy (with v0.3 support) here https://dbcook.svn.sourceforge.net/svnroot/dbcook/trunk/dbcook/misc/aggregator/ now after rereading your stuff i'm even less sure if what i say is relevant. svilen --~--~---------~--~----~------------~-------~--~----~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~----------~----~----~----~------~----~------~--~---