On 9/28/07, Glauco <[EMAIL PROTECTED]> wrote:
>  Yes...
>
>  this is the example
>
>
>
>  session.query( UnitaAziendale ).order_by(Anagrafica.c.nome)


Ok... do you remember about  the ".join()" or ".outerjoin()" I told you before ?
That's how you should declare you Query:



q = session.query( UnitaAziendale
).outerjoin('anagrafica').order_by(Anagrafica.c.nome)

OR

q = session.query( UnitaAziendale
).join('anagrafica').order_by(Anagrafica.c.nome)



Then try printing the q.compile()

You will see a join between "unita_aziendale" and "anagrafica"
(twice)... One of these "anagrafica" joins is to provide you the
columns regarding 'anagrafica' property... The other "anagrafica" join
is because we will force SA to make this join, so we can order by
(Anagrafica.c.nome).


"Why can SA use the same 'anagrafica' join to give us the columns and
to provide the order by clause ?" - you may ask...

One of the reasons is because you can always change the rules about a
Query... like: "what if I don't need to eagerload the 'anagrafica'
objects ?"


q = session.query(UnitaAziendale).options(lazyload('anagrafica'))
q = q.outerjoin('anagrafica').order_by(Anagrafica.c.nome)
print q.compile()


See ? No "anon_xxxx" prefix this time.. because you told SA to just
query UnitaAziendale objects... (but ordering by another table column)

Try swapping the ".outerjoin('anagrafica')" for ".join('anagrafica')"
and see the differences... It may affect your result set...



>  i hope this is enough, if not i can send all to you by mail.

It was enough to me...

Hope I could help... if no, don't hesitate to tell us..

Cheers,

Roger

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