summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/orm/interfaces.py
diff options
context:
space:
mode:
Diffstat (limited to 'lib/sqlalchemy/orm/interfaces.py')
-rw-r--r--lib/sqlalchemy/orm/interfaces.py56
1 files changed, 49 insertions, 7 deletions
diff --git a/lib/sqlalchemy/orm/interfaces.py b/lib/sqlalchemy/orm/interfaces.py
index d12c20a2c..45ab9b48f 100644
--- a/lib/sqlalchemy/orm/interfaces.py
+++ b/lib/sqlalchemy/orm/interfaces.py
@@ -107,7 +107,9 @@ class MapperProperty(_MappedAttribute, InspectionAttr, util.MemoizedSlots):
"""
return {}
- def setup(self, context, entity, path, adapter, **kwargs):
+ def setup(
+ self, context, query_entity, path, mapper,
+ adapter, column_collection, populators, **kw):
"""Called by Query for the purposes of constructing a SQL statement.
Each MapperProperty associated with the target mapper processes the
@@ -116,6 +118,17 @@ class MapperProperty(_MappedAttribute, InspectionAttr, util.MemoizedSlots):
"""
+ def setup_for_missing_attribute(
+ self, context, query_entity, path, mapper, populators, **kw):
+ """Setup a strategy for a Query where this property was not yet
+ included.
+
+ This function can do everything that setup() does, *except* attempt
+ to modify the SQL query; the method may be called after the query
+ has already been emitted and results are being received.
+
+ """
+
def cascade_iterator(self, type_, state, visited_instances=None,
halt_on=None):
"""Iterate through instances related to the given instance for
@@ -481,13 +494,31 @@ class StrategizedProperty(MapperProperty):
def _get_strategy_by_cls(self, cls):
return self._get_strategy(cls._strategy_keys[0])
- def setup(self, context, entity, path, adapter, **kwargs):
- loader = self._get_context_loader(context, path)
- if loader and loader.strategy:
- strat = self._get_strategy(loader.strategy)
+ def setup(
+ self, context, query_entity, path, mapper,
+ adapter, column_collection, populators, **kw):
+
+ loadopt = self._get_context_loader(context, path)
+ if loadopt and loadopt.strategy:
+ strat = self._get_strategy(loadopt.strategy)
else:
strat = self.strategy
- strat.setup_query(context, entity, path, loader, adapter, **kwargs)
+
+ strat.setup_query(
+ context, query_entity, path, mapper,
+ adapter, column_collection, populators, loadopt, **kw)
+
+ def setup_for_missing_attribute(
+ self, context, query_entity, path, mapper,
+ populators, **kw):
+
+ loadopt = self._get_context_loader(context, path)
+ if loadopt and loadopt.strategy:
+ strat = self._get_strategy(loadopt.strategy)
+ else:
+ strat = self.strategy
+ strat.setup_for_missing_attribute(
+ context, query_entity, path, mapper, populators, loadopt, **kw)
def do_init(self):
self._strategies = {}
@@ -585,7 +616,9 @@ class LoaderStrategy(object):
def init_class_attribute(self, mapper):
pass
- def setup_query(self, context, entity, path, loadopt, adapter, **kwargs):
+ def setup_query(
+ self, context, query_entity, path, mapper,
+ adapter, column_collection, populators, loadopt, **kw):
"""Establish column and other state for a given QueryContext.
This method fulfills the contract specified by MapperProperty.setup().
@@ -595,5 +628,14 @@ class LoaderStrategy(object):
"""
+ def setup_for_missing_attribute(
+ self, context, query_entity, path, mapper,
+ populators, loadopt, **kw):
+ """Establish loader behavior for an attribute that's not accommodated
+ by the query.
+
+ This is used for polymorphic loading when a subclass load is detected.
+ """
+
def __str__(self):
return str(self.parent_property)