Ok, thanks for the response.  What's the timeframe for the 1.1 release?  In 
the meantime, I will have a look into adding my own class_ attribute, or 
using the Comparator.  

I tried something like

setattr(datadb.Cube.plateifu, "class_", datadb.Cube.id.class_)

but it didn't seem to work.  But I'll dig a bit deeper.  If I can't get 
something working with a 1.0X release, I'll try the 1.1 in bitbucket. 


On Tuesday, May 10, 2016 at 2:32:22 PM UTC-4, Mike Bayer wrote:
>
> 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.
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