Add InstrumentedAttribute support for get_tables

This commit is contained in:
Konsta Vesterinen
2014-10-20 18:15:10 +03:00
parent 72718fad01
commit 92efb4d326

View File

@@ -214,17 +214,20 @@ def get_tables(mixed):
return [mixed]
elif isinstance(mixed, sa.Column):
return [mixed.table]
elif isinstance(mixed, sa.orm.attributes.InstrumentedAttribute):
return mixed.parent.tables
elif isinstance(mixed, sa.orm.query._ColumnEntity):
mixed = mixed.expr
mapper = get_mapper(mixed)
polymorphic_mappers = get_polymorphic_mappers(mapper)
if polymorphic_mappers:
tables = sum((m.tables for m in polymorphic_mappers), [])
tables = mapper.tables
else:
tables = mapper.tables
if isinstance(mixed, sa.orm.attributes.InstrumentedAttribute):
mixed = mixed.class_
return tables