summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/orm/attributes.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2013-03-09 13:24:54 -0500
committerMike Bayer <mike_mp@zzzcomputing.com>2013-03-09 13:24:54 -0500
commit852e9954aaec7205e7ebaf3d0b232e1e8ff20e63 (patch)
treeeda5a78cc0f9a496c4b662885a4b5810669d6dc6 /lib/sqlalchemy/orm/attributes.py
parentd2a256a3ad48341e013b6e7a3e911495e5b5d31a (diff)
downloadsqlalchemy-852e9954aaec7205e7ebaf3d0b232e1e8ff20e63.tar.gz
A meaningful :attr:`.QueryableAttribute.info` attribute is
added, which proxies down to the ``.info`` attribute on either the :class:`.schema.Column` object if directly present, or the :class:`.MapperProperty` otherwise. The full behavior is documented and ensured by tests to remain stable. [ticket:2675]
Diffstat (limited to 'lib/sqlalchemy/orm/attributes.py')
-rw-r--r--lib/sqlalchemy/orm/attributes.py43
1 files changed, 43 insertions, 0 deletions
diff --git a/lib/sqlalchemy/orm/attributes.py b/lib/sqlalchemy/orm/attributes.py
index 891aef862..3eda127fd 100644
--- a/lib/sqlalchemy/orm/attributes.py
+++ b/lib/sqlalchemy/orm/attributes.py
@@ -174,6 +174,49 @@ class QueryableAttribute(interfaces._MappedAttribute,
# TODO: conditionally attach this method based on clause_element ?
return self
+
+ @util.memoized_property
+ def info(self):
+ """Return the 'info' dictionary for the underlying SQL element.
+
+ The behavior here is as follows:
+
+ * If the attribute is a column-mapped property, i.e.
+ :class:`.ColumnProperty`, which is mapped directly
+ to a schema-level :class:`.Column` object, this attribute
+ will return the :attr:`.SchemaItem.info` dictionary associated
+ with the core-level :class:`.Column` object.
+
+ * If the attribute is a :class:`.ColumnProperty` but is mapped to
+ any other kind of SQL expression other than a :class:`.Column`,
+ the attribute will refer to the :attr:`.MapperProperty.info` dictionary
+ associated directly with the :class:`.ColumnProperty`, assuming the SQL
+ expression itself does not have it's own ``.info`` attribute
+ (which should be the case, unless a user-defined SQL construct
+ has defined one).
+
+ * If the attribute refers to any other kind of :class:`.MapperProperty`,
+ including :class:`.RelationshipProperty`, the attribute will refer
+ to the :attr:`.MapperProperty.info` dictionary associated with
+ that :class:`.MapperProperty`.
+
+ * To access the :attr:`.MapperProperty.info` dictionary of the :class:`.MapperProperty`
+ unconditionally, including for a :class:`.ColumnProperty` that's
+ associated directly with a :class:`.schema.Column`, the attribute
+ can be referred to using :attr:`.QueryableAttribute.property`
+ attribute, as ``MyClass.someattribute.property.info``.
+
+ .. versionadded:: 0.8.0
+
+ .. seealso::
+
+ :attr:`.SchemaItem.info`
+
+ :attr:`.MapperProperty.info`
+
+ """
+ return self.comparator.info
+
@util.memoized_property
def parent(self):
"""Return an inspection instance representing the parent.