I'm trying to build a query system where given a filter parameter name, I 
can figure out which DeclarativeBase class it is attached to.  I need to do 
this for a mix of standard InstrumentedAttributes and Hybrid 
Properties/Expressions. I have several Declarative Base classes with 
hybrid properties / expressions defined, in addition to the standard 
InstrumentedAttributes from the actual table.  mydb.dataModelClasses.Cube 
for example.

For a standard attribute, I can access the class using the class_ variable. 
 

Standard Attribute on the DeclarativeBase class Cube
type(datadb.Cube.id)
sqlalchemy.orm.attributes.InstrumentedAttribute

print datadb.Cube.id.class_
mydb.DataModelClasses.Cube

What's the best way to retrieve this same information for a hybrid 
expression?  My expressions are other types, thus don't have the class_ 
attribute.  One example of my hybrid property defined in the Cube class

    @hybrid_property
    def plateifu(self):
        return '{0}-{1}'.format(self.plate, self.ifu.name)

    @plateifu.expression
    def plateifu(cls):
        return func.concat(Cube.plate, '-', IFUDesign.name)

type(datadb.Cube.plateifu)
sqlalchemy.sql.functions.concat

Since this property is now a function concat, what's the best way to 
retrieve the name of the class that this property is attached to, namely '
mydb.DataModelClasses.Cube'?  It doesn't seem to have a .class_ or .parent 
attribute.  Is there a way to add a new attribute onto my hybrid columns 
that let me access the parent class?

I need to do this for a variety of hybrid properties/expressions, that are 
all constructed in unique ways.  This particular example is a function 
concat, however I have others that are of type 
sqlalchemy.sql.elements.BinaryExpression. 

Is there a way to generically do this no matter the type of hybrid 
expression I define?

Thanks. 
  

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

Reply via email to