Add support for Column objects in get_mapper

This commit is contained in:
Konsta Vesterinen
2014-11-03 14:02:42 +02:00
parent 67d8271652
commit 0f62046bf8
3 changed files with 20 additions and 2 deletions

View File

@@ -4,6 +4,12 @@ Changelog
Here you can see the full list of changes between each SQLAlchemy-Utils release.
0.27.7 (2014-11-03)
^^^^^^^^^^^^^^^^^^^
- Added support for Column objects in get_mapper
0.27.6 (2014-10-29)
^^^^^^^^^^^^^^^^^^^

View File

@@ -77,6 +77,8 @@ def get_mapper(mixed):
"""
if isinstance(mixed, sa.orm.query._MapperEntity):
mixed = mixed.expr
elif isinstance(mixed, sa.Column):
mixed = mixed.table
if isinstance(mixed, sa.orm.Mapper):
return mixed
@@ -227,8 +229,6 @@ def get_tables(mixed):
tables = sum((m.tables for m in polymorphic_mappers), [])
else:
tables = mapper.tables
return tables

View File

@@ -56,6 +56,18 @@ class TestGetMapper(object):
sa.inspect(self.Building)
)
def test_column(self):
assert (
get_mapper(self.Building.__table__.c.id) ==
sa.inspect(self.Building)
)
def test_column_of_an_alias(self):
assert (
get_mapper(sa.orm.aliased(self.Building.__table__).c.id) ==
sa.inspect(self.Building)
)
class TestGetMapperWithQueryEntities(TestCase):
def create_models(self):