On Feb 4, 2008, at 11:29 AM, Utku Altinkaya wrote:

>
> Greetings,
>
>
> I have Users class with relation to Address which have relation to
> Cities, all are eager loaded. I want to sort the Users query with the
> name field of the cities table. But if I order by City.name the cities
> table is joined to the actual query. How can I explain it to use the
> cities.name field in the join statement ? Or any different are welcome
> also.
>

two ways.

historically we've told people not to rely upon eager loading for  
ordering or join criterion:

http://www.sqlalchemy.org/trac/wiki/FAQ#ImusinglazyFalsetocreateaJOINOUTERJOINandSQLAlchemyisnotconstructingthequerywhenItrytoaddaWHEREORDERBYLIMITetc.whichreliesupontheOUTERJOIN

while that FAQ entry seems kind of finalish, you can achieve some  
basic ordering against the eager load if you set order_by=None on the  
parent mapper (or set it to None with your Query;  
query.order_by(None)), and then set order_by as desired on each  
relation() (which can also be None, such as on your Address  
ordering).   that way the ordering of the eagerly loaded collection  
affects the ordering overall.



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

Reply via email to