On Fri, Jun 11, 2010 at 4:16 AM, jpeck <peck.j...@gmail.com> wrote:
> I am trying to map to a simple read only property. According to the
> docs, I *think* I am supposed to use synonym. The problem is that I am
> getting a None value for the mapped descriptor's column.
>

Ok, so I got this working with synonym, but I am not sure I am doing
this the best way. As long as I access the descriptor before an insert
or update, the synonym worked ok.

I ended up using a MapperExtension like so:

class UpdatePropertiesExtension(MapperExtension):
    def __init__(self, properties):
        self.properties = properties

    def _update_properties(self, instance):
        for p in self.properties:
            getattr(instance, p)

    def before_insert(self, mapper, connection, instance):
        self._update_properties(instance)

    def before_update(self, mapper, connection, instance):
        self._update_properties(instance)


This works fine for me, but I'm wondering if there is a better way to do this?

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalch...@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