Hi all

I'm quite new to sqlalchemy and I'm very impressed by how much 
experience this work is showing in its implementation.

But I've been brooding over a seemingly simple problem whose solution is 
always just a step away...

Having a legacy db with simplified relations

aaa = Table( 'AAA',
   metadata,
   Column('pk1',  String(2),  primary_key=True),
   Column('pk2',  String(4),  primary_key=True),
   Column('pk3',  Integer,    primary_key=True))

bbb = Table( 'BBB',
   metadata,
   Column('pk1',  String(2),  primary_key=True),
   Column('pk2',  String(4),  primary_key=True),
   Column('pk3',  Integer,    primary_key=True))

No problem to define a one to many relation from AAA > BBB so far.
Now, as it always goes with 'legacy', some clever guy added another 
table, again with a one to many relation from AAA > CCC with a catch:

ccc = Table( 'CCC',
   metadata,
   Column('pk4',  String(6),  primary_key=True),
   Column('pk3',  Integer,    primary_key=True))

where pk4 is the concatenation of pk1 and pk2.

I tried to use column_property:
mapper(AAA, aaa,
   order_by = None,
   properties = {
     'pk4' : column_property((aaa.c.pk1 + ord.c.pk2).label('pk4')),
     'bbbs': relation(),
     'cccs': relation()})

But every mentioning of pk4 throws an attribute error.

I tried to use composite:

class PK4(object):
   def __init__(self, pk1, pk2):
       self.pk1= pk1
       self.pk2= pk2

   def __composite_values__(self):
       return [self.pk1, self.pk2]

   def __eq__(self, other):
       return other.pk1 == self.pk1 and other.pk2 == self.pk2

   def __ne__(self, other):
       return not self.__eq__(other)

I tried to use column_property:
mapper(AAA, aaa,
   order_by = None,
   properties = {
     'pk4' : composite(PK4, aaa.c.pk1, aaa.c.pk2),
     'bbbs': relation(),
     'cccs': relation()})

Attribute errors as well in relation, but now the columns pk1 and pk2 
being in the composite vanish from aaa. Maybe I'm just blind, but I'm 
also grateful for a shove in the right direction.

Thank you, Werner Thie

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