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/query.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/query.py')
-rw-r--r-- | lib/sqlalchemy/orm/query.py | 36 |
1 files changed, 19 insertions, 17 deletions
diff --git a/lib/sqlalchemy/orm/query.py b/lib/sqlalchemy/orm/query.py index 53cf227ee..147b4cf0c 100644 --- a/lib/sqlalchemy/orm/query.py +++ b/lib/sqlalchemy/orm/query.py @@ -18,7 +18,9 @@ ORM session, whereas the ``Select`` construct interacts directly with the database to return iterable result sets. """ +from __future__ import absolute_import +import collections from itertools import chain from . import ( @@ -2942,6 +2944,7 @@ class Query(object): entity.setup_context(self, context) if context.statement is not None: + context._predefined_statement = True return context for rec in context.create_eager_joins: @@ -3044,6 +3047,13 @@ class Query(object): statement.append_order_by(*context.eager_order_by) context._setup_column_processors( + enumerate( + col for (label, col) in statement._columns_plus_names + ), + outer_adapter + ) + + context._setup_column_processors( enumerate(context.primary_columns, 0) ) context._setup_column_processors( @@ -3093,7 +3103,7 @@ class Query(object): # that have been established context._setup_column_processors( enumerate( - context.primary_columns + context.secondary_columns + col for (label, col) in statement._columns_plus_names ) ) @@ -3317,7 +3327,7 @@ class _MapperEntity(_QueryEntity): else: only_load_props = refresh_state = None - _instance = loading.instance_processor( + _instance = loading._instance_processor( self.mapper, props_toload, context, @@ -3331,18 +3341,6 @@ class _MapperEntity(_QueryEntity): ) context.loaders.append((self._label_name, _instance)) - # TODO: this needs to be in instance_processor() - # and needs a getter fn. a special entry in - # populators should be used here - # if self._polymorphic_discriminator is not None and \ - # self._polymorphic_discriminator \ - # is not self.mapper.polymorphic_on: - # - # if adapter: - # pd = adapter.columns[self._polymorphic_discriminator] - # else: - # pd = self._polymorphic_discriminator - # context.primary_columns.append(pd) def __str__(self): return str(self.mapper) @@ -3690,6 +3688,7 @@ class QueryContext(object): froms = () for_update = None order_by = False + _predefined_statement = False def __init__(self, query): @@ -3723,11 +3722,14 @@ class QueryContext(object): self.attributes = query._attributes.copy() self.loaders = [] - def _setup_column_processors(self, cols): - d = dict( - (col, idx) for idx, col in cols + def _setup_column_processors(self, cols, adapter=None): + d = collections.defaultdict( + lambda: -1, + [(col, idx) for idx, col in cols] ) for col, fn in self.column_processors: + if adapter: + col = adapter.columns[col] fn(d[col]) |