Add class alias support
* Add class alias support for get_hybrid_properties function
This commit is contained in:
@@ -4,6 +4,12 @@ Changelog
|
|||||||
Here you can see the full list of changes between each SQLAlchemy-Utils release.
|
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)
|
0.30.14 (2015-07-23)
|
||||||
^^^^^^^^^^^^^^^^^^^^
|
^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
|
|||||||
@@ -92,4 +92,4 @@ from .types import ( # noqa
|
|||||||
WeekDaysType
|
WeekDaysType
|
||||||
)
|
)
|
||||||
|
|
||||||
__version__ = '0.30.14'
|
__version__ = '0.30.15'
|
||||||
|
|||||||
@@ -734,14 +734,27 @@ def get_hybrid_properties(model):
|
|||||||
get_hybrid_properties(Category).keys() # ['lowercase_name']
|
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
|
.. versionchanged: 0.26.7
|
||||||
This function now returns a dictionary instead of generator
|
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
|
:param model: SQLAlchemy declarative model or mapper
|
||||||
"""
|
"""
|
||||||
return dict(
|
return dict(
|
||||||
(key, prop)
|
(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)
|
if isinstance(prop, hybrid_property)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -35,3 +35,10 @@ class TestGetHybridProperties(object):
|
|||||||
list(get_hybrid_properties(sa.inspect(self.Category)).keys()) ==
|
list(get_hybrid_properties(sa.inspect(self.Category)).keys()) ==
|
||||||
['lowercase_name']
|
['lowercase_name']
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def test_aliased_class(self):
|
||||||
|
assert (
|
||||||
|
list(get_hybrid_properties(sa.orm.aliased(self.Category)).keys())
|
||||||
|
==
|
||||||
|
['lowercase_name']
|
||||||
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user