[sqlalchemy] Re: order_by on related object attribute?

2007-04-20 Thread Gaetan de Menten

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
-~--~~~~--~~--~--~---



[sqlalchemy] Re: order_by on related object attribute?

2007-04-18 Thread Michael Bayer


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.

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.



--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---