diff --git a/CHANGES.rst b/CHANGES.rst index 41d03ec..39eb01b 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -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) ^^^^^^^^^^^^^^^^^^^ diff --git a/sqlalchemy_utils/functions/orm.py b/sqlalchemy_utils/functions/orm.py index 6a6eaa0..5f73236 100644 --- a/sqlalchemy_utils/functions/orm.py +++ b/sqlalchemy_utils/functions/orm.py @@ -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 diff --git a/tests/functions/test_get_mapper.py b/tests/functions/test_get_mapper.py index bdcb8d6..9e075a4 100644 --- a/tests/functions/test_get_mapper.py +++ b/tests/functions/test_get_mapper.py @@ -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):