Roger Demetrescu ha scritto:
> Hi Glauco
>
> On 9/27/07, Glauco <[EMAIL PROTECTED]> wrote:
>   
>> Hi all,
>> how can i know the correct name of a table compiled into qry   that SA
>> has automatically aliased?
>>
>> for example:
>> a join b join c join d..
>>
>> sqlalchemy has created something like
>>
>> select blabla
>> from a AS anon_b406
>> join.....
>>
>>
>> when i try to put into an "order by a"
>> obviously the qry goes wrong.
>>
>> invalid reference to FROM-clause entry for table "a"
>>     
>
>
> Does your question has any relation with the patch that allows
> ordering or related objects's attributes ?  ;)
>   
no no Roger, i will install next days...

> If so, I think I know what you are doing wrong... you must use Query's
>  .join() or .outerjoin() method. Like that:
>
> session.query(ObjectA).join('property_b').order_by(ObjectB.c.foobar)
>
> Where 'foobar' maps to the column from B table which you want to use
> to sort your data...
>   

This is correct Roger, but my problem is when in this example SA compile 
the qry using alias

select ... form table_a as alias1..... table_b as alias2....... order by 
table_a.column1


in this case the qry is wrong because the order by  is incorrect.

take a look

*sqlalchemy.exceptions.SQLError: ('(ProgrammingError) missing 
FROM-clause entry for table "azienda"\n',

SELECT unita_aziendale.id_anagrafica AS unita_aziendale_id_anagrafica,
        unita_aziendale.bdn_data_ultima_modifica AS 
unita_aziendale_bdn_data_ultima_modifica,
        unita_aziendale.bdn_specie AS unita_aziendale_bdn_specie,
        unita_aziendale.ts_ultima_modifica AS 
unita_aziendale_ts_ultima_modifica,
**        **unita_aziendale.id_precedente AS unita_aziendale_id_precedente,
**        **unita_aziendale.id AS unita_aziendale_id,
        <CUT>
**        **anon_b406.data_aggiornamento AS anon_b406_data_aggiornamento,
        unita_aziendale.bdn_flag_carne_latte AS 
unita_aziendale_bdn_flag_carne_latte

FROM produzione, unita_aziendale
LEFT OUTER JOIN anagrafica AS anon_b3be ON anon_b3be.id = 
unita_aziendale.id_anagrafica
LEFT OUTER JOIN scheda_totali AS anon_b406 ON unita_aziendale.id = 
anon_b406.id_unita_aziendale

WHERE <SOME CONDITION>

ORDER BY azienda.id_asl ASC, anon_b3be.id, anon_b406.id_unita_aziendale'


Glauco

*

-- 
+------------------------------------------------------------+
                                  Glauco Uri - Programmatore
                                    glauco(at)allevatori.com 
                               
  Sfera Carta Software(R)      [EMAIL PROTECTED]
  Via Bazzanese,69  Casalecchio di Reno(BO) - Tel. 051591054 
+------------------------------------------------------------+



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

Reply via email to