summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/orm/mapper.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2012-12-29 19:31:28 -0500
committerMike Bayer <mike_mp@zzzcomputing.com>2012-12-29 19:31:28 -0500
commitb30ef87d27898434188462455f3c850297e335d1 (patch)
tree58eddbad639eb05e1756d81db57822e8a4465ae2 /lib/sqlalchemy/orm/mapper.py
parent559b83312c44f7ebfe94bf7bd3b2de3133c5af9e (diff)
downloadsqlalchemy-b30ef87d27898434188462455f3c850297e335d1.tar.gz
Extended the :doc:`/core/inspection` system so that all Python descriptors
associated with the ORM or its extensions can be retrieved. This fulfills the common request of being able to inspect all :class:`.QueryableAttribute` descriptors in addition to extension types such as :class:`.hybrid_property` and :class:`.AssociationProxy`. See :attr:`.Mapper.all_orm_descriptors`.
Diffstat (limited to 'lib/sqlalchemy/orm/mapper.py')
-rw-r--r--lib/sqlalchemy/orm/mapper.py37
1 files changed, 37 insertions, 0 deletions
diff --git a/lib/sqlalchemy/orm/mapper.py b/lib/sqlalchemy/orm/mapper.py
index 626105b5e..6d8fa4dbb 100644
--- a/lib/sqlalchemy/orm/mapper.py
+++ b/lib/sqlalchemy/orm/mapper.py
@@ -1502,12 +1502,49 @@ class Mapper(_InspectionAttr):
returned, inclding :attr:`.synonyms`, :attr:`.column_attrs`,
:attr:`.relationships`, and :attr:`.composites`.
+ .. seealso::
+
+ :attr:`.Mapper.all_orm_descriptors`
"""
if _new_mappers:
configure_mappers()
return util.ImmutableProperties(self._props)
+ @util.memoized_property
+ def all_orm_descriptors(self):
+ """A namespace of all :class:`._InspectionAttr` attributes associated
+ with the mapped class.
+
+ These attributes are in all cases Python :term:`descriptors` associated
+ with the mapped class or its superclasses.
+
+ This namespace includes attributes that are mapped to the class
+ as well as attributes declared by extension modules.
+ It includes any Python descriptor type that inherits from
+ :class:`._InspectionAttr`. This includes :class:`.QueryableAttribute`,
+ as well as extension types such as :class:`.hybrid_property`,
+ :class:`.hybrid_method` and :class:`.AssociationProxy`.
+
+ To distinguish between mapped attributes and extension attributes,
+ the attribute :attr:`._InspectionAttr.extension_type` will refer
+ to a constant that distinguishes between different extension types.
+
+ When dealing with a :class:`.QueryableAttribute`, the
+ :attr:`.QueryableAttribute.property` attribute refers to the
+ :class:`.MapperProperty` property, which is what you get when referring
+ to the collection of mapped properties via :attr:`.Mapper.attrs`.
+
+ .. versionadded:: 0.8.0
+
+ .. seealso::
+
+ :attr:`.Mapper.attrs`
+
+ """
+ return util.ImmutableProperties(
+ dict(self.class_manager._all_sqla_attributes()))
+
@_memoized_configured_property
def synonyms(self):
"""Return a namespace of all :class:`.SynonymProperty`