In fact we used to use metaclass way of handling this problem, but for some unknown reason it was changed to monkey patching _as_declarative :|

Couple months ago I've read your post:
http://techspot.zzzeek.org/2011/05/17/magic-a-new-orm/
where there is a similar approach (classes generate relation properties). I thought that in current SQLA it could be done also with column properties, but if not it's fine, it's not a big of a deal... just wanted to know if I can avoid this "hack".

Regards
Tomasz Jezierski
Tefnet

W dniu 21.09.2012 16:27, Michael Bayer pisze:
using a class there which replaces itself means you've developed a custom 
creational pattern.  A less hacky approach would be to subclass 
DeclarativeMeta, and just pass it to your Base:

from sqlalchemy.ext.declarative import DeclarativeMeta

class TefnetMeta(DeclarativeMeta):
     def __init__(cls, classname, bases, dict_):
         for key, value in dict_.items():
             if isinstance(value, TefProperty):
                 dict_[key] = value._config(cls, key)
         super(TefnetMeta, cls).__init__(classname, bases, dict_)

Base = declarative_base(metaclass=TefnetMeta)



On Sep 21, 2012, at 10:17 AM, Tefnet Developers wrote:

My example is just the shortest code I could come up with to show a problem, 
but in production it doesn't look like this.
We're using class inheritance, metaclass features etc, so changing it to 
function is not an option for us :|


W dniu 21.09.2012 15:59, Michael Bayer pisze:
my immediate thought on that code is to replace TefProperty with a function, 
since you are discarding TefProperty in any case:


def propInt():
     return sa.Column(key, Integer)

not sure how the previous Extension version of the code did this differently, 
this is really a class creational pattern.



On Sep 21, 2012, at 2:59 AM, Tefnet Developers wrote:

Hi,
we are trying to migrate our old *Extension based SQLA code to new - event 
based.
We also have class based properties that we want to keep. With old SQLA we have had to 
monkey-patch _as_declarative function to populate our properties. I wonder if it is 
possible to avoid doing it with events? The only close one we found is 
"mapper_configured", but I'm afraid it is executed too late. Anyway... I've 
prepared some short example code. If you could take a look and advise if/how it can be 
done...

To check out where is the problem change USE_EVENT value from True to False.
https://gist.github.com/3757273

Regards,
Tomasz Jezierski
Tefnet

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

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


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