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