summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2015-01-14 12:02:41 -0500
committerMike Bayer <mike_mp@zzzcomputing.com>2015-01-14 12:02:41 -0500
commit41307cd7339a2a2aee0a3dd9c8b994df99d7eedb (patch)
tree0549b66dbfe8475fecc21693523ee052ecb7c72e
parentb63aae2c232f980a47aa2a635c35dfa45390f451 (diff)
downloadsqlalchemy-41307cd7339a2a2aee0a3dd9c8b994df99d7eedb.tar.gz
- add new section to ORM referring to runtime inspection API,
more links, attempt to fix #3290
-rw-r--r--doc/build/orm/mapping_styles.rst49
1 files changed, 49 insertions, 0 deletions
diff --git a/doc/build/orm/mapping_styles.rst b/doc/build/orm/mapping_styles.rst
index e6be00ef7..7571ce650 100644
--- a/doc/build/orm/mapping_styles.rst
+++ b/doc/build/orm/mapping_styles.rst
@@ -119,3 +119,52 @@ systems ultimately create the same configuration, consisting of a :class:`.Table
user-defined class, linked together with a :func:`.mapper`. When we talk about
"the behavior of :func:`.mapper`", this includes when using the Declarative system
as well - it's still used, just behind the scenes.
+
+Runtime Intropsection of Mappings, Objects
+==========================================
+
+The :class:`.Mapper` object is available from any mapped class, regardless
+of method, using the :ref:`core_inspection_toplevel` system. Using the
+:func:`.inspect` function, one can acquire the :class:`.Mapper` from a
+mapped class::
+
+ >>> from sqlalchemy import inspect
+ >>> insp = inspect(User)
+
+Detailed information is available including :attr:`.Mapper.columns`::
+
+ >>> insp.columns
+ <sqlalchemy.util._collections.OrderedProperties object at 0x102f407f8>
+
+This is a namespace that can be viewed in a list format or
+via individual names::
+
+ >>> list(insp.columns)
+ [Column('id', Integer(), table=<user>, primary_key=True, nullable=False), Column('name', String(length=50), table=<user>), Column('fullname', String(length=50), table=<user>), Column('password', String(length=12), table=<user>)]
+ >>> insp.columns.name
+ Column('name', String(length=50), table=<user>)
+
+Other namespaces include :attr:`.Mapper.all_orm_descriptors`, which includes all mapped
+attributes as well as hybrids, association proxies::
+
+ >>> insp.all_orm_descriptors
+ <sqlalchemy.util._collections.ImmutableProperties object at 0x1040e2c68>
+ >>> insp.all_orm_descriptors.keys()
+ ['fullname', 'password', 'name', 'id']
+
+As well as :attr:`.Mapper.column_attrs`::
+
+ >>> list(insp.column_attrs)
+ [<ColumnProperty at 0x10403fde0; id>, <ColumnProperty at 0x10403fce8; name>, <ColumnProperty at 0x1040e9050; fullname>, <ColumnProperty at 0x1040e9148; password>]
+ >>> insp.column_attrs.name
+ <ColumnProperty at 0x10403fce8; name>
+ >>> insp.column_attrs.name.expression
+ Column('name', String(length=50), table=<user>)
+
+.. seealso::
+
+ :ref:`core_inspection_toplevel`
+
+ :class:`.Mapper`
+
+ :class:`.InstanceState`