diff --git a/CHANGES.rst b/CHANGES.rst index 914284a..0f54467 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -7,7 +7,7 @@ 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 +- Added support for Column and ColumnEntity objects in get_mapper - Made make_order_by_deterministic add deterministic column more aggressively diff --git a/sqlalchemy_utils/functions/orm.py b/sqlalchemy_utils/functions/orm.py index 5f73236..457211c 100644 --- a/sqlalchemy_utils/functions/orm.py +++ b/sqlalchemy_utils/functions/orm.py @@ -79,6 +79,8 @@ def get_mapper(mixed): mixed = mixed.expr elif isinstance(mixed, sa.Column): mixed = mixed.table + elif isinstance(mixed, sa.orm.query._ColumnEntity): + mixed = mixed.expr if isinstance(mixed, sa.orm.Mapper): return mixed diff --git a/tests/functions/test_get_mapper.py b/tests/functions/test_get_mapper.py index 9e075a4..89088ee 100644 --- a/tests/functions/test_get_mapper.py +++ b/tests/functions/test_get_mapper.py @@ -91,6 +91,10 @@ class TestGetMapperWithQueryEntities(TestCase): sa.inspect(self.Building) ) + def test_column_entity(self): + query = self.session.query(self.Building.id) + assert get_mapper(query._entities[0]) == sa.inspect(self.Building) + class TestGetMapperWithMultipleMappersFound(object): def setup_method(self, method):