diff options
| author | Mike Bayer <mike_mp@zzzcomputing.com> | 2008-10-04 22:39:19 +0000 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2008-10-04 22:39:19 +0000 |
| commit | a9a4da62cfe4a7dbe6afff1f993e161e8243a6dc (patch) | |
| tree | 9e98a22be2db887741208afe1176698e56f62d02 /lib | |
| parent | f4871697774a512bebf0dd11866d3b0e8eb54b91 (diff) | |
| download | sqlalchemy-a9a4da62cfe4a7dbe6afff1f993e161e8243a6dc.tar.gz | |
- using contains_eager() against an alias combined with an overall query alias repaired - the
contains_eager adapter wraps the query adapter, not vice versa. Test coverage added.
- contains_eager() will now add columns into the "primary" column collection within Query._compile_context(), instead
of the "secondary" collection. This allows those columns to get wrapped within the subquery generated
by limit/offset in conjunction with an ORM-generated eager join.
Eager strategy also picks up on context.adapter in this case to deliver the columns during result load.
contains_eager() is now compatible with the subquery generated by a regular eager load
with limit/offset. [ticket:1180]
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/sqlalchemy/orm/strategies.py | 30 |
1 files changed, 21 insertions, 9 deletions
diff --git a/lib/sqlalchemy/orm/strategies.py b/lib/sqlalchemy/orm/strategies.py index 308266cd8..7439ab68b 100644 --- a/lib/sqlalchemy/orm/strategies.py +++ b/lib/sqlalchemy/orm/strategies.py @@ -595,24 +595,28 @@ class EagerLoader(AbstractRelationLoader): path = path + (self.key,) # check for user-defined eager alias - if ("eager_row_processor", path) in context.attributes: - clauses = context.attributes[("eager_row_processor", path)] + if ("user_defined_eager_row_processor", path) in context.attributes: + clauses = context.attributes[("user_defined_eager_row_processor", path)] adapter = entity._get_entity_clauses(context.query, context) if adapter and clauses: - context.attributes[("eager_row_processor", path)] = clauses = adapter.wrap(clauses) + context.attributes[("user_defined_eager_row_processor", path)] = clauses = clauses.wrap(adapter) elif adapter: - context.attributes[("eager_row_processor", path)] = clauses = adapter - + context.attributes[("user_defined_eager_row_processor", path)] = clauses = adapter + + add_to_collection = context.primary_columns + else: clauses = self._create_eager_join(context, entity, path, adapter, parentmapper) if not clauses: return context.attributes[("eager_row_processor", path)] = clauses + + add_to_collection = context.secondary_columns for value in self.mapper._iterate_polymorphic_properties(): - value.setup(context, entity, path + (self.mapper.base_mapper,), clauses, parentmapper=self.mapper, column_collection=context.secondary_columns) + value.setup(context, entity, path + (self.mapper.base_mapper,), clauses, parentmapper=self.mapper, column_collection=add_to_collection) def _create_eager_join(self, context, entity, path, adapter, parentmapper): # check for join_depth or basic recursion, @@ -691,7 +695,15 @@ class EagerLoader(AbstractRelationLoader): return clauses def _create_eager_adapter(self, context, row, adapter, path): - if ("eager_row_processor", path) in context.attributes: + if ("user_defined_eager_row_processor", path) in context.attributes: + decorator = context.attributes[("user_defined_eager_row_processor", path)] + # user defined eagerloads are part of the "primary" portion of the load. + # the adapters applied to the Query should be honored. + if context.adapter and decorator: + decorator = decorator.wrap(context.adapter) + elif context.adapter: + decorator = context.adapter + elif ("eager_row_processor", path) in context.attributes: decorator = context.attributes[("eager_row_processor", path)] else: if self._should_log_debug: @@ -789,8 +801,8 @@ class LoadEagerFromAliasOption(PropertyOption): prop = mapper.get_property(propname, resolve_synonyms=True) self.alias = prop.target.alias(self.alias) - query._attributes[("eager_row_processor", paths[-1])] = sql_util.ColumnAdapter(self.alias) + query._attributes[("user_defined_eager_row_processor", paths[-1])] = sql_util.ColumnAdapter(self.alias) else: - query._attributes[("eager_row_processor", paths[-1])] = None + query._attributes[("user_defined_eager_row_processor", paths[-1])] = None |
