Thanks Diez and Daniel for the responses. It seems that this is the
way to go, but it's not quite there yet: now I can indeed load the
correct lass instance for my queries, but it seems to be restricted to
inherited classes already loaded in my current module. What would like
to do is being to do something more similar to (conceptually!):


class Job(Base):
   class_path = Column(Unicode(64)) # for example "CustomJobA"
module_path = Column(Unicode(64)) # maybe "plugins.myplugin.path.to.module"

   def get_class_name(self):
         modz = __import__(self.module_path, fromlist=["True"])
         clazz  = getattr(modz, self.class_path)
        globals()[clazz.__name__] = clazz
   class_name = property(get_class_name)
   __mapper_args__ = {'polymorphic_on': class_name}


then, in plugins/myplugin/path/to/module.py:

class CustomJobA(Job):
   __mapper_args__ = {'polymorphic_identity': 'CustomJobA'}

Where I don't necessary have the class CustomJobA from module
plugins.myplugin.path.to.module imported in the first place, but it
will be loaded. Of course, what I just wrote up there seems reaally
hacky and probably there's a better way? To be honest, I haven't even
tested if it even works yet.

Sounds like a bad idea for me. I'm not really that deep into SA metadata, but I guess it relies heavily on the metadata being complete when querying and so forth.

So I guess you should setup your plugin system in a way that initializes Job-subclasses before invoking metadata.create_all() somehow.

Diez

--
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to [email protected].
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