On Aug 22, 2010, at 8:45 AM, Eduardo Robles Elvira wrote:

> On May 15 2008, 6:27 pm, Michael Bayer <mike...@zzzcomputing.com>
> wrote:
>> On May 15, 2008, at 12:12 PM, J. Cliff Dyer wrote:
>>> How can I use this field for polymorphism?  Is it possible?
>> 
>> polymorphicdiscriminators are currently table-local scalar columns.  
>> So if you had a many-to-one of discriminators, youd currently have to  
>> encode the discriminator to the primarykeyidentifier of each  
>> discriminotor.  We will eventually allow a python function to be used  
>> as a discriminator as well which you can use to add a level of  
>> abstraction to this (you'd preload the list of discriminiator objects  
>> and again map based on primarykey).
> 
> Hello!
> 
> Two years later.. :P Are we going to get a python function to be used
> as a discriminator soon? I would think that it would not be very
> difficult to implement, right? As shown in my previous emails in the
> thread "Model factory", that would solve my problem.

Discriminator functions don't solve your issue.  Your table already has a 
discriminator column, so in that regard, determination of "discriminiator", 
which is all that proposed function would ever do, is already provided by the 
built in functionality.

You're looking to rig a non-SQLAlchemy creational pattern into your objects.   
The MapperExtension method create_instance() provides this capability.    
Another option is to just use @reconstructor, and just set self.__class__ = 
<whatever class you want>.

I agree with other posters that the whole idea is a little hacky and if it were 
me, I would ensure that all Job subclasses are configured and mapped ahead of 
time.  Failing that, if I truly needed to have module paths in the database 
(which I wouldn't, since I think encoding language-specific constructs in a 
relational database is a bad idea), I would either have my app do a "SELECT 
DISTINCT" of all those modules at startup, pre-load all the classes and map 
them, or, I'd have Job load an "impl" based on that module information and 
proxy methods to the dynamically loaded object (which is not very different 
from the @reconstructor approach except for structure).


> I have the python
> function already written, but I don't know how to make sqlalchemy call
> to it. I thought that using a composite field should work, but it
> doesn't because as you say, it's not a table-local scalar column. If
> the problem is the proxy_set is not set, maybe I can set the proxy_set
> var to the composite_field somehow?



> 
> Regards,
>   Eduardo Robles Elvira.
> 
> -- 
> 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.
> 

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