summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/orm/properties.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2020-04-20 12:24:40 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2020-04-20 15:59:37 -0400
commit6abbda34ebb2c154ccae12d749968fe72f27f372 (patch)
treeed8d093e3153e0866107e5222a176b464ecd2bd7 /lib/sqlalchemy/orm/properties.py
parentfe35828eefc00e12e01df25f6fd942eecde1a686 (diff)
downloadsqlalchemy-6abbda34ebb2c154ccae12d749968fe72f27f372.tar.gz
Add ColumnProperty.Comparator.expressions
Added an accessor :attr:`.ColumnProperty.Comparator.expressions` which provides access to the group of columns mapped under a multi-column :class:`.ColumnProperty` attribute. Fixes: #5262 Change-Id: I44cf53ff0e6cf76a0c90eee4638ca96da3df8088
Diffstat (limited to 'lib/sqlalchemy/orm/properties.py')
-rw-r--r--lib/sqlalchemy/orm/properties.py30
1 files changed, 29 insertions, 1 deletions
diff --git a/lib/sqlalchemy/orm/properties.py b/lib/sqlalchemy/orm/properties.py
index 1022f4ef6..4cf316ac7 100644
--- a/lib/sqlalchemy/orm/properties.py
+++ b/lib/sqlalchemy/orm/properties.py
@@ -337,7 +337,7 @@ class ColumnProperty(StrategizedProperty):
"""
- __slots__ = "__clause_element__", "info"
+ __slots__ = "__clause_element__", "info", "expressions"
def _memoized_method___clause_element__(self):
if self.adapter:
@@ -354,12 +354,40 @@ class ColumnProperty(StrategizedProperty):
)
def _memoized_attr_info(self):
+ """The .info dictionary for this attribute."""
+
ce = self.__clause_element__()
try:
return ce.info
except AttributeError:
return self.prop.info
+ def _memoized_attr_expressions(self):
+ """The full sequence of columns referenced by this
+ attribute, adjusted for any aliasing in progress.
+
+ .. versionadded:: 1.3.17
+
+ """
+ if self.adapter:
+ return [
+ self.adapter(col, self.prop.key)
+ for col in self.prop.columns
+ ]
+ else:
+ # no adapter, so we aren't aliased
+ # assert self._parententity is self._parentmapper
+ return [
+ col._annotate(
+ {
+ "parententity": self._parententity,
+ "parentmapper": self._parententity,
+ "orm_key": self.prop.key,
+ }
+ )
+ for col in self.prop.columns
+ ]
+
def _fallback_getattr(self, key):
"""proxy attribute access down to the mapped column.