use query.options(extension(MyExtension()))

On Mar 13, 2007, at 12:53 PM, percious wrote:

>
> I think I came up with a decent solution for this:  I do something
> like:
>
> extension = MyMapperExtension()
> for mapper in mapper_registry.values():
>     mapper.extension = extension
>     mapper._compile_extensions()
>
> If you want all classes currently defined in the metadata to map to
> your new extension.  This is actually working quite well.
>
> cheers.
> chris
>
> On Feb 9, 11:33 am, "Michael Bayer" <[EMAIL PROTECTED]> wrote:
>> I should add that you *can* be more creative, and construct each  
>> mapper
>> with aMapperExtensionat the beginning which later can be "enabled"  
>> with
>> a "hello world" callable.  i.e.
>>
>> class MyExt(MapperExtension):
>>     def __init__(self):
>>         self.func = None
>>     def after_insert(self, ...):
>>         if self.func:
>>              self.func()
>>
>> extension = MyExt()
>> mapper(foo, bar, extension=extension)
>> mapper(foo2, bar2, extension=extension)
>> mapper(foo3, bar3, extension=extension)
>>
>> ... do stuff ...
>>
>> def helloworld():
>>     print "hello world"
>> extension.func = helloworld
>>
>> ... do stuff ...
>>
>> percious wrote:
>>
>>> question.
>>
>>> Lets say I have a series of table definitions, and a series of  
>>> objects
>>> linked to the tables with a bunch of mappers.
>>
>>> First question:  Is there a way to get from the table definitions in
>>> the metadata to the Mapper?
>>
>>> Second question:  If I create aMapperExtension, can I then link  
>>> it to
>>> the mapper associated with a table?
>>
>>> What I want to do is create a simple application that goes  
>>> through the
>>> tables defined within a metadata, and create an extension so that
>>> every time a table entry is added it prints 'hello world' to the
>>> screen.
>>
>>> TIA
>>> -chris
>
>
> >


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