Add support for InstrumentedAttributes in get_mapper

This commit is contained in:
Konsta Vesterinen
2014-10-20 12:09:56 +03:00
parent f354adf894
commit f9e12b99a9
2 changed files with 7 additions and 0 deletions

View File

@@ -83,6 +83,8 @@ def get_mapper(mixed):
mixed = mixed.element mixed = mixed.element
if isinstance(mixed, AliasedInsp): if isinstance(mixed, AliasedInsp):
return mixed.mapper return mixed.mapper
if isinstance(mixed, sa.orm.attributes.InstrumentedAttribute):
mixed = mixed.class_
if isinstance(mixed, sa.Table): if isinstance(mixed, sa.Table):
mappers = [ mappers = [
mapper for mapper in mapperlib._mapper_registry mapper for mapper in mapperlib._mapper_registry

View File

@@ -42,6 +42,11 @@ class TestGetMapper(object):
sa.inspect(self.Building) sa.inspect(self.Building)
) )
def test_instrumented_attribute(self):
assert (
get_mapper(self.Building.id) == sa.inspect(self.Building)
)
def test_table_alias(self): def test_table_alias(self):
alias = sa.orm.aliased(self.Building.__table__) alias = sa.orm.aliased(self.Building.__table__)
assert ( assert (