On Mon, Oct 4, 2010 at 5:45 PM, Michael Bayer <mike...@zzzcomputing.com> wrote:
>
> On Oct 4, 2010, at 8:26 PM, Ritesh Nadhani wrote:
>
>> Hello
>>
>> This has been making me pull my hair for quite sometime now :)
>>
>> I am trying to use MapperExtension and I have a code like:
>> http://bpaste.net/show/9936/
>>
>> Basically, I share the model across two apps, so I want one with the
>> extension and one without. Thus the need to use one of the internal
>> methods:
>>
>> __mapper__,exception.push(....)
>
>>
>> Unfortunately, it the whole thing works when I use, __mapper_args__
>> but does not if I add it dynamically using the above method. Though,
>> other methods like before_update, row_translate get called in both
>> ways of setup. Just not reconstruct_instance, which I what I wanted.
>>
>> I will now startup a debugger but I was wondering if anybody knew
>> about it or its a bug or its just not possible?
>
> It's not a bug since ad-hoc addition of extensions is not public API.   The 
> mapper checks its extensions for this particular hook when its created and 
> sets an extra event listener on the class if present.
>
> 0.7 will allow ad-hoc listeners in a more flexible way.
>
> There is actually a "listener" interface for this in 0.6 which is 
> semi-private.  It will be changing a little bit in 0.7 (whereas 
> MapperExtension will remain backwards compatible for at least through 
> 0.7/0.8).  If you wanted to try that its:
>
>        from sqlalchemy.orm.attributes import manager_of_class
>
>        def reconstruct(instance):
>                print "reconstruct!"
>
>        manager_of_class(SomeTable).events.add_listener('on_load', reconstruct)
>
> In this case its likely much easier to set up __mapper_args__ as a callable 
> on your class instead (see the examples in declarative regarding mixins - the 
> same technique works on the class itself), or to use the @reconstructor 
> decorator inside a conditional:
>
> class MyClass(Base):
>        if my_app_config_foo_bar:
>               �...@reconstructor
>                def reconstruct(self):
>                        print "reconstruct!"
>
>
>
>
> --
> 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.
>
>

Aha. Thanks. I guess I will wait till 0.7 to use the feature.

I understood the reconstructor way but not sure the mixin way. I will
go now and reread the docs on the subject.


-- 
Ritesh

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