It appears this doesn't currently work as expected (ver 0.5rc2, Python 
2.5) when the tables are reflected (autoload = True).

I have two reflected (legacy) tables that define similar properties with 
different names and different units (both are time, one is in seconds 
the other in minutes). e.g:

class A(object):
    pass

class B(object):
    pass

a = A()
a.timeunits = 60 # A.timeunit is in seconds
b = B()
b.time_units = 1 # B.time_unit is in minutes


I'd like to present a coherent interface for these two class in my ORM 
layer. Both classes should appear to have a property 'timeunit' that is 
expressed in seconds. Both classes should be able to use 'timeunits' in 
filter expressions and suchlike and (A.timeunits = 60) == (B.timeunits = 
60) == (B.time_units * 60).

Reading this example:
http://www.sqlalchemy.org/docs/04/mappers.html#advdatamapping_mapper_overriding

I tried the following kind of approach:

class B(object):
    def _set_time_unit(self, value):
       self.timeunit = value / float(60)
    def _get_time_unit(self)
       return self.timeunit = value * 60
    time_unit = property(_get_time_unit, _set_time_unit)

Mapper(B, table_b, properties = { "time_unit" : synonym("timeunit", 
map_column = True})

But what happens (if you add a few prints and whatnot to illustrate) is 
that the property setter is never called either when objects are being 
instanced from the database or when setting the property of an existing 
instance of B. Seems that the reflection mechanism has hijacked (via 
it's own descriptors I'm imagining) attribute access in a way that makes 
it impossible for this kind of symmetrical translation to occur.

I would have thought this might be a relatively common problem with 
legacy databases so I'd thought check with the list to see if a solution 
or workaround had already been found. Couldn't find an obvious parallel 
in the list archives so I'm appealing to the group memory for some help 
on this.

Am I just getting this wrong or have I just come against something that 
just can't currently be done ? I can thing of alternative schemes that 
might work but they seem to lose me the ability to use the synonym as 
spelled in filter expressions

Thanks in advance,


Toby Bradshaw
--
Ideaworks 3d,
London, UK.

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