diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2015-02-26 16:40:40 -0500 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2015-02-26 18:18:48 -0500 |
commit | 50fcf349fb0afab78af8bb05066143aea7519359 (patch) | |
tree | b15938fb6ef44803ae4e722057d73b79c1fe604c /lib/sqlalchemy/orm/interfaces.py | |
parent | 84a894c635b7b47731a7ae1def0090d57e9b9e79 (diff) | |
download | sqlalchemy-row_proc_integration.tar.gz |
- polymorphic loading, working very rudimentallyrow_proc_integration
running orm2010, the whole approach adds callcounts.
code is more complex, less reliable, pretty much a total
bust.
will try to see if create_row_processor can remain but
be called against either "result" or a context namespace
ahead of time, and if this somehow can be used to simplify
the need to call upon strategy lookup twice.
Diffstat (limited to 'lib/sqlalchemy/orm/interfaces.py')
-rw-r--r-- | lib/sqlalchemy/orm/interfaces.py | 56 |
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) |