Awesome, this is exactly what I needed. Thanks Michael.

On Sat, Dec 29, 2012 at 4:36 PM, Michael Bayer <mike...@zzzcomputing.com>wrote:

>
> On Dec 29, 2012, at 5:45 PM, Michael Bayer wrote:
>
> >
> > On Dec 29, 2012, at 3:03 AM, Gerald Thibault wrote:
> >
> >> I'll post a test case later if needed, but this is more of a technical
> question so i don't think it will be needed.
> >>
> >> When i use iterate_properties on a class with a hybrid_property, it's
> not shown in the list. I am trying to 'extract' fields from classes in
> order to automatically build forms from them. iterate_properties was useful
> for getting most info, but eventually i had to start using 'for k in
> dir(class)' to get access to association proxies on the classes. I would
> use getattr(cls, k) to get the object, but for hybrid properties this calls
> fget, and directly returns a BinaryExpression, rather than the property
> itself. The only way I can find to access the actual hybrid_property object
> is via vars(cls), and then, this doesn't contain hybrid properties defined
> on the bases which are being used by the class.
> >>
> >> Is there a way built into sqlalchemy to get all hybrid_property objects
> for a class, both those declared on the active class and those declared on
> the base classes? I'm mainly interested in determining whether a setter has
> been provided on the property, to determine if it's readonly or not.
> >
> >
> > There's no API system of reading non-MapperProperty objects, which
> includes all the various descriptors we have in sqlalchemy.ext.      It
> might be nice to add such an API to do so and make this an extension of the
> 0.8 inspect() system, but anyway for now when you read class-bound
> descriptors like this, you have to work around the fact that they have
> classbound behavior, which means you can't use getattr().
>
> I've added this feature to the tip for 0.8.0:
>
> from sqlalchemy import inspect
>
> insp = inspect(MyClass)   # note this is just the Mapper, as usual
>
> for k, v in insp.all_orm_descriptors:
>     if v.extension_type is associationproxy.ASSOCIATION_PROXY:
>         # ...
>     elif v.extension_type is hybrid.HYBRID_PROPERTY
>        # ...
>
>    # etc.
>
> see
> http://docs.sqlalchemy.org/en/latest/orm/mapper_config.html#sqlalchemy.orm.mapper.Mapper.all_orm_descriptors
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "sqlalchemy" group.
> To post to this group, send email to sqlalchemy@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 sqlalchemy@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