summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/orm/properties.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2012-04-23 12:03:54 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2012-04-23 12:03:54 -0400
commit54017d9de202ed67072a352ce2f6dbfd74bf48f3 (patch)
treea632045bd8a5e7d5932d69d5f436bc27f1b9788d /lib/sqlalchemy/orm/properties.py
parent8f35f7a803c67f4ab0620686592a021a24e4b331 (diff)
parentf7bb3b17e6df09caa56c20c722364fc52edf7afc (diff)
downloadsqlalchemy-54017d9de202ed67072a352ce2f6dbfd74bf48f3.tar.gz
merge patch for [ticket:2208]. This still needs documentation.
Diffstat (limited to 'lib/sqlalchemy/orm/properties.py')
-rw-r--r--lib/sqlalchemy/orm/properties.py31
1 files changed, 29 insertions, 2 deletions
diff --git a/lib/sqlalchemy/orm/properties.py b/lib/sqlalchemy/orm/properties.py
index 424795ee4..fd64e7b81 100644
--- a/lib/sqlalchemy/orm/properties.py
+++ b/lib/sqlalchemy/orm/properties.py
@@ -99,6 +99,13 @@ class ColumnProperty(StrategizedProperty):
else:
self.strategy_class = strategies.ColumnLoader
+ @property
+ def expression(self):
+ """Return the primary column or expression for this ColumnProperty.
+
+ """
+ return self.columns[0]
+
def instrument_class(self, mapper):
if not self.instrument:
return
@@ -276,7 +283,6 @@ class RelationshipProperty(StrategizedProperty):
else:
self.backref = backref
-
def instrument_class(self, mapper):
attributes.register_descriptor(
mapper.class_,
@@ -805,6 +811,27 @@ class RelationshipProperty(StrategizedProperty):
dest_state.get_impl(self.key).set(dest_state,
dest_dict, obj, None)
+ def _value_as_iterable(self, state, dict_, key,
+ passive=attributes.PASSIVE_OFF):
+ """Return a list of tuples (state, obj) for the given
+ key.
+
+ returns an empty list if the value is None/empty/PASSIVE_NO_RESULT
+ """
+
+ impl = state.manager[key].impl
+ x = impl.get(state, dict_, passive=passive)
+ if x is attributes.PASSIVE_NO_RESULT or x is None:
+ return []
+ elif hasattr(impl, 'get_collection'):
+ return [
+ (attributes.instance_state(o), o) for o in
+ impl.get_collection(state, dict_, x, passive=passive)
+ ]
+ else:
+ return [(attributes.instance_state(x), x)]
+
+
def cascade_iterator(self, type_, state, dict_, visited_states, halt_on=None):
#assert type_ in self.cascade
@@ -819,7 +846,7 @@ class RelationshipProperty(StrategizedProperty):
get_all_pending(state, dict_)
else:
- tuples = state.value_as_iterable(dict_, self.key,
+ tuples = self._value_as_iterable(state, dict_, self.key,
passive=passive)
skip_pending = type_ == 'refresh-expire' and 'delete-orphan' \