Add support for InstrumentedAttributes in get_mapper
This commit is contained in:
@@ -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
|
||||||
|
@@ -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 (
|
||||||
|
Reference in New Issue
Block a user