in 1.1 these hybrids will have the class_ attribute like other attributes.
Until then you can probably add your own class_ attribute to the object which you are returning. Also, using a custom Comparator class (see the example in the hybrid docs) will also return an instrumented attribute that should have a class_ attribute.
Or you could try using the 1.1 hybrid_property class yourself, it should be compatible with 1.0. The commits are illustrated in https://bitbucket.org/zzzeek/sqlalchemy/issues/3653 but you can probably just use the hybrid.py straight from the git repository with 1.0.
On 05/10/2016 02:01 PM, Brian Cherinka wrote:
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 printdatadb.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 defplateifu(self): return'{0}-{1}'.format(self.plate,self.ifu.name) @plateifu.expression defplateifu(cls): returnfunc.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 <mailto:sqlalchemy+unsubscr...@googlegroups.com>. To post to this group, send email to sqlalchemy@googlegroups.com <mailto:sqlalchemy@googlegroups.com>. Visit this group at https://groups.google.com/group/sqlalchemy. For more options, visit https://groups.google.com/d/optout.
-- 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.