On 4/18/07, Michael Bayer <[EMAIL PROTECTED]> wrote: > On Apr 18, 2007, at 12:21 AM, Chris Shenton wrote: > > > > > I'm using SQLAlchemy with Pylons and query my 'system' table and order > > by their client_id field like: > > > > from er.models import System, Vendor, Client > > sys = self.session.query(System).select(System.c.lastseen > > > self.this_week, > > order_by= > > [System.c.client_id, > > > > System.c.lastseen]) > > > > it would look like: > > query(System).select(System.c.lastseen > self.this.week, from_obj= > [system_table.join(client)], order_by=[client.c.name]) > > or alternatively > > query(System).select(and_(System.c.lastseen > self.this.week, > system_table.c.client_id==client.c.client_id), order_by=[client.c.name]) > > i.e. you arent doing any kind of "column selection" here, you just > need the cols to be in the order by.
By the way, lately I've been wishing SQLAlchemy would add a column (and possibly its table) automatically to the select clause if I do an order by a column which is not in the currently selected columns. I mean that you could write: query(System).select(System.c.lastseen > self.this.week, order_by=[client.c.name]) and it would figure out that the client.c.name is not in the selection, and would add it (or rather would add the join you describe above). I *think* this shouldn't be hard to do since SA can already figure out the join criterion itself if you add the column manually. When using, the "SQL" layer of SQLAlchemy, I don't mind having to write the joins myself. But when using the ORM, I'd expect this to be done for me. And it would be even better if this worked also for relations and mappers. The use case I am most interested in (and I haven't found a nice solution for it yet) is the order_by argument for mappers. Yes, I know, that would mean I'd always have a join whenever I select from that mapper. Strange use case, but well, I need to do that sometimes. > there is a way to get extra columns in the "SELECT" clause of a > mapper query in the most recent version of SA but thats not what > youre looking for here. Or is what I describe possible by using what you say in the above paragraph???? -- Gaƫtan de Menten http://openhex.org --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
