On Oct 31, 2009, at 9:19 AM, Ghost wrote:

>
> Documentation for Using Descriptors has following example:
>
> ====
> class EmailAddress(object):
>   def _set_email(self, email):
>      self._email = email
>   def _get_email(self):
>      return self._email
>   email = property(_get_email, _set_email)
>
> mapper(MyAddress, addresses_table, properties={
>    '_email': addresses_table.c.email
> })
>
> ...
>
> mapper(EmailAddress, addresses_table, properties={
>    'email': synonym('_email', map_column=True)
> })
> ====
>
> Firstly, should "MyAddress" be "EmailAddress"?

that's likely fixed in the most recent docs (which are 0.6)

>
> Secondly, can one not create a plain property without using synonym()?
> I do not understand the need for 'copying' a column, only to change
> it's behaviour using property(). I would expect something more like
> this:
>
> ====
> class MyStuff(object):
>   def _set_useful_property(self, value):
>      self.useful_property= value
>   def _get_useful_property(self):
>      return self.useful_property
>   useful_property = property(_get_useful_property,
> _set_useful_property)
>
> mapper(MyStuff, stuff_table, properties={
>    'useful_property': MyStuff.useful_property
> })
> ====
>
> Have I misunderstood the methods by which to add mapped properties?

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).



--~--~---------~--~----~------------~-------~--~----~
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 
sqlalchemy+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to