Hi Sanjay,

Mapper Extension is the way to do this. I use one we call our "compiler"
extension, it fires events before database insert, datase update and after
database load; you can use these events to modify the object as needed. You
can probably hack this into what you need:

class CompilerExtension(MapperExtension):
    """ Allows for "compilation" of sub-items into binary blobs stored on
the parent """
    def before_insert(self, mapper, connection, instance):
        instance.oninsert()
        return EXT_PASS
    def before_update(self, mapper, connection, instance):
        instance.onupdate()
        return EXT_PASS
    def populate_instance(self, mapper, selectcontext, row, instance,
identitykey, isnew):
        if isnew:
            mapper.populate_instance(selectcontext, instance, row,
identitykey, isnew)
            instance.onload()
            return None
        return EXT_PASS

The code for the "onload" is a bit tangled, because SA does not (yet)
provide an "after" db load, just a "before". I've asked Mike for another
"after" hook (bump, bump), but I think he may have forgotten (bump) about
(bump) it (bump...).

Rick






On 2/28/07, Sanjay <[EMAIL PROTECTED]> wrote:
>
>
> Hi All,
>
> Needing help badly. Summarizing my problem: I need to run some
> initialization code after an object is retrieved from database. Say I
> have a table Person(first_name, last_name), I need that while the
> object is fetched, another instance variable named full_name is
> assigned as firstname + last_name.
>
> Tried to use MapperExtension by going through the suggestions in some
> threads, in the FAQ and the doc, but could not secceed. Also, could
> not find out how to use __new__ in this scenario. Surely my
> noviceness, either in Python or SQLAlchemy.
>
> Some sample code or specific guidence could help a lot.
>
> thanks
> Sanjay
>
>
> >
>

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