On Nov 16, 2012, at 1:05 AM, Gerald Thibault wrote:
> I have an association proxy set up to proxy an attribute from a parent to a one to one child. That proxied column does not show when I do class.__mapper__.iterate_properties. How would I go about adding a property so the proxied columns are exposed via iterate_properties?
> I'll add some code if necessary, but this seems like a pretty straight-forward question that I probably just overlooked in the docs.
the mapper().iterate_properties accessor only refers to MapperProperty objects, which are all of those attributes that the mapper() associates with the database in some way.
the association proxy is not a MapperProperty - it is just a Python descriptor that has proxying behavior from one attribute to another. It can in theory be used to proxy data between any two attributes, independently of SQLAlchemy (there might be a few bits of logic that look for SQLAlchemy-related attributes to help it decide how the proxying should be done, though).
If you're looking to iterate through the attributes associated with the class, the Python dir() function can get you this. You can limit the results to those classes you need using isinstance():
for attr in dir(MyClass):
if hasattr(attr, "property"):
elif isinstance(attr, association_proxy):