On Aug 10, 2011, at 11:58 AM, Dirk Makowski wrote: > Hi Michael, > > thank you for the quick answer. object_mapper() solves the UnmappedClassError. > > The depicted technique, however, lists just the 'physical' columns. Those > defined with relationship() or injected by backref are not included.
> I'm not Luke, but I also used the source (thank you for providing it) ;) > which pointed me to sqlalchemy.orm.properties.RelationshipProperty. With this > I am able to list both kinds of columns: > > mapper = object_mapper(p) > attrs = [] > for prop in mapper.iterate_properties: > if isinstance(prop, ColumnProperty): > attrs.append(prop.key) > elif isinstance(prop, RelationshipProperty): > attrs.append(prop.key) > attrs.sort() > print "Columns:", attrs OK, little terminology gap here, there's only one kind of "column" in SQLAlchemy and that's "Column", a relationship() is not in any way describable as a "column", so we just call them at the class level "attributes" and at the mapper level "properties". You're looking at properties, each of which is MapperProperty. They all have a key, so easy enough: print "Attribute keys:", ",".join(prop.key for prop in object_mapper(p).iterate_properties) ColumnProperty and RelationshipProperty are the two prominent types, others include CompositeProperty and SynonymProperty. -- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
