"Jorge Vargas" <[EMAIL PROTECTED]> writes:

> If I have tables X and Y which contain data from two diferent sources (other
> aplication for example, or a dump from another database) and I want to load
> them both into SQLObject the normal thing will be to create class A and B that
> map to table x and y. Now what if I want to manage those 2 tables in my
> logic as a single Object. Could I do something like this
> #seudo code not python below
> class C(SQLObject):
>   field1=x.field1
>   field2=y.field2
>   filed3=x.field3
>   field4=somefunction(field3)
> I know I could create C as a class that doesn't extends SQLObject and map it's
> values to A and B's fields but that seems a little ugly to me, not to
> mention I have to load A and B all the time even if I wont use them.
> how about SQLAlchemy or other product?

I dunno about SQLAlchemy, but I do create a view and then I map this view to
an SQLObject class.  This way I can do anything with it.  (PostgreSQL allows
using rules to update views...)

For the unique id column I concatenate each table's id and define te idType as
str.  Something like:


class PrecoParaClientes(SQLObject):
    
    class sqlmeta:
        cacheValues = False
        table = 'v_precos_clientes_segmentos_analises'
        lazyUpdate = True
        idType = str

    segmentoID = IntCol()
    analiseID = IntCol()
    tabelaID = IntCol()
    nome = UnicodeCol()
    precoRotina = DecimalCol(size = 19, precision = 4)
    precoUrgente = DecimalCol(size = 19, precision = 4)


I created this view as

 SELECT a.id::text || '.'::text || a.segmento_id::text || '.'::text || 
p.id::text AS id, 
        a.segmento_id, a.nome, p.analise_id, p.preco_urgente, p.preco_rotina, 
        p.tabela_id 
 FROM neolab.analises a, 
      neolab.precos p 
 WHERE a.id = p.analise_id;


-- 
Jorge Godoy      <[EMAIL PROTECTED]>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"TurboGears" 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/turbogears
-~----------~----~----~----~------~----~------~--~---

Reply via email to