Add class alias support

* Add class alias support for get_hybrid_properties function
This commit is contained in:
Konsta Vesterinen
2015-07-28 10:56:19 +03:00
parent a2b665bb7b
commit 4cde5438a5
4 changed files with 28 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.30.15 (2015-07-28)
^^^^^^^^^^^^^^^^^^^^
- Added support for aliased classes in get_hybrid_properties utility function
0.30.14 (2015-07-23)
^^^^^^^^^^^^^^^^^^^^

View File

@@ -92,4 +92,4 @@ from .types import ( # noqa
WeekDaysType
)
__version__ = '0.30.14'
__version__ = '0.30.15'

View File

@@ -734,14 +734,27 @@ def get_hybrid_properties(model):
get_hybrid_properties(Category).keys() # ['lowercase_name']
This function also supports aliased classes
::
get_hybrid_properties(
sa.orm.aliased(Category)
).keys() # ['lowercase_name']
.. versionchanged: 0.26.7
This function now returns a dictionary instead of generator
.. versionchanged: 0.30.15
Added support for aliased classes
:param model: SQLAlchemy declarative model or mapper
"""
return dict(
(key, prop)
for key, prop in sa.inspect(model).all_orm_descriptors.items()
for key, prop in get_mapper(model).all_orm_descriptors.items()
if isinstance(prop, hybrid_property)
)

View File

@@ -35,3 +35,10 @@ class TestGetHybridProperties(object):
list(get_hybrid_properties(sa.inspect(self.Category)).keys()) ==
['lowercase_name']
)
def test_aliased_class(self):
assert (
list(get_hybrid_properties(sa.orm.aliased(self.Category)).keys())
==
['lowercase_name']
)