On 4/19/07, Michael Bayer <[EMAIL PROTECTED]> wrote: > > > On Apr 19, 2007, at 9:39 AM, Gaetan de Menten wrote: > > > 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 would agree up to the point that the table gets added, which is > what happens if you add columns to the SELECT clause of a select; the > table gets appended to the FROM clause.
Good. > but i dont agree in creating > JOIN objects automatically with no explicit specification that that's > whats desired (as usual, i am open to all sorts of explicit methods > of specifications...although we have plenty for specifying "join on a > relationship" at this point). > > the query above I would express generatively as: > > query(System).filter(System.c.lastseen > self.this.week).order_by > (client.c.name).join('clients').list() > > Maybe it would also be handy to have join() accept a Table as well as > a Class argument, and have it figure out the auto-thing in those > cases as well. all that is fine with me (since theres no other > meaning you could get from join(SomeOtherClass) ). Good too. But would this work in all cases? Even if the class is mapped several times, mapped to an arbitrary selectable and so on? > cant we just agree that adding the join automatically is an egregious > case of implicit over explicit ? Yes, you are perfectly right, and I fully agree the "autojoin" part was a pretty stupid suggestion. > considering that it is *so* > *easy* to join on a relationship now: > > query(MyClass).join('somerelation').select(table2.c.name=='foo') Yes, [and here I was going to say] "but it doesn't solve my order by a related column as a mapper option problem" but then suddenly realized that what I want is already possible. Mapping my class against the join between system and client, than using order_by="client.c.name" should work, right? Sorry for the trouble. Note that it doesn't change the fact that what you agreed to above still seem like a good idea. -- 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 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 -~----------~----~----~----~------~----~------~--~---