Hi all,
from a given class I'd like to determine which attributes are columns, not
only physical columns present in the underlying table, but also those from a
relationship(). The FAQ <http://www.sqlalchemy.org/trac/wiki/FAQ> seems to
provide an answer ("What's the best way to figure out which attributes are
columns, given a class"), but the proposed solution throws an
"sqlalchemy.orm.exc.UnmappedClassError: Class '<pym.models.usrmgr.Principal
object at 0x3a69c10>' is not mapped" error in my setup.
I'm using 0.7.2. with declarative classes, e.g.
DbBase = declarative_base()
class Principal(DbBase, PymMixin):
__tablename__ = "principal"
__table_args__ = {'schema': 'pym'}
is_enabled = Column(Boolean, nullable=False, default=False)
...
Does is matter that I try to read the attributes from a query?
qry = sess.query(Principal)
for p in qry:
print p.display_name
# Determine columns in last looped entity
mapper = class_mapper(p) #<---- this throws UnmappedClassError
attrs = set()
for prop in mapper.iterate_properties:
if isinstance(prop, ColumnProperty):
attrs.add(prop.key)
print "Columns:", attrs
Thanks for your help,
Dirk
--
You received this message because you are subscribed to the Google Groups
"sqlalchemy" group.
To view this discussion on the web visit
https://groups.google.com/d/msg/sqlalchemy/-/aDMx6g7syHsJ.
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.