>
> if the purpose of "useful_property" is to deal with the value  
> associated with a mapped column that shares the same name, the column  
> itself needs to be mapped to a new attribute name.   The examples in  
> the documentation illustrate how to apply this new attribute name  
> which will express the value directly associated with the column, and  
> in the case of synonym(), how to make your new descriptor act just  
> like the column-associated attribute at the instrumented class level  
> (i.e. in the construction of expressions).   In your MyStuff example,  
> any access to "self.useful_property", by rule of that's how Python  
> works, will access your "useful_property" descriptor - so that code as  
> is will cause a recursion overflow.
>
> OTOH if "useful_property" has no relationship to any one particular  
> column, no ORM configuration is required (but you still need to fix  
> your recursive access to useful_property).


How does one go about doing that? If you need to use the orm to query
the database for columns that do not exist in the table itself, do you
not need to add these to the mapper? Can that be done without
synonyms?

I have thought of a sensical example to illustrate what I am trying to
do: You want a field for the age of a person even though you only
store their date of birth in the database table. You want to be able
to query the database by filtering using the age column so I assume
you need to add it to the mapper.

Should it be done in the following way or is another approach
favoured?

===
class Person(object):
   def _set_age(self, value):
      pass
   def _get_age(self):
      return date.today() - self.date_of_birth
   age = property(_get_age, _set_age)

mapper(Person, person_table, properties={
    'age': synonym("date_of_birth")
})
===

Thank you for your help..
--~--~---------~--~----~------------~-------~--~----~
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