diff options
| author | Mike Bayer <mike_mp@zzzcomputing.com> | 2009-09-16 20:35:27 +0000 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2009-09-16 20:35:27 +0000 |
| commit | 0d860209039b89ac85564d7dead7cf613813a01a (patch) | |
| tree | ccba4a0c47ab1f45a7f0c1f7863c4d860c17933c /lib/sqlalchemy | |
| parent | 72d9a6ff607dc98c3a0c0c8f9ce3b4e66d4b1180 (diff) | |
| download | sqlalchemy-0d860209039b89ac85564d7dead7cf613813a01a.tar.gz | |
- move the tests to test_query
- the option needs the original mapper to pull the prop from, in the case the eagerload is *from* a joined-table subclass mapper.
had to change the contract of PropertyOption to pass
an additional list "mappers" which contains the actual parent mappers.
Diffstat (limited to 'lib/sqlalchemy')
| -rw-r--r-- | lib/sqlalchemy/orm/interfaces.py | 25 | ||||
| -rw-r--r-- | lib/sqlalchemy/orm/strategies.py | 9 |
2 files changed, 20 insertions, 14 deletions
diff --git a/lib/sqlalchemy/orm/interfaces.py b/lib/sqlalchemy/orm/interfaces.py index 5dffa6774..8f0db5352 100644 --- a/lib/sqlalchemy/orm/interfaces.py +++ b/lib/sqlalchemy/orm/interfaces.py @@ -668,11 +668,11 @@ class PropertyOption(MapperOption): self._process(query, False) def _process(self, query, raiseerr): - paths = self.__get_paths(query, raiseerr) + paths, mappers = self.__get_paths(query, raiseerr) if paths: - self.process_query_property(query, paths) + self.process_query_property(query, paths, mappers) - def process_query_property(self, query, paths): + def process_query_property(self, query, paths, mappers): pass def __find_entity(self, query, mapper, raiseerr): @@ -718,7 +718,8 @@ class PropertyOption(MapperOption): path = None entity = None l = [] - + mappers = [] + # _current_path implies we're in a secondary load # with an existing path current_path = list(query._current_path) @@ -739,6 +740,7 @@ class PropertyOption(MapperOption): entity = query._entity_zero() path_element = entity.path_entity mapper = entity.mapper + mappers.append(mapper) prop = mapper.get_property(token, resolve_synonyms=True, raiseerr=raiseerr) key = token elif isinstance(token, PropComparator): @@ -746,8 +748,9 @@ class PropertyOption(MapperOption): if not entity: entity = self.__find_entity(query, token.parententity, raiseerr) if not entity: - return [] + return [], [] path_element = entity.path_entity + mappers.append(prop.parent) key = prop.key else: raise sa_exc.ArgumentError("mapper option expects string key or list of attributes") @@ -757,7 +760,7 @@ class PropertyOption(MapperOption): continue if prop is None: - return [] + return [], [] path = build_path(path_element, prop.key, path) l.append(path) @@ -765,15 +768,17 @@ class PropertyOption(MapperOption): path_element = mapper = token._of_type else: path_element = mapper = getattr(prop, 'mapper', None) + if path_element: path_element = path_element.base_mapper - + + # if current_path tokens remain, then # we didn't have an exact path match. if current_path: - return [] + return [], [] - return l + return l, mappers class AttributeExtension(object): """An event handler for individual attribute change events. @@ -823,7 +828,7 @@ class StrategizedOption(PropertyOption): def is_chained(self): return False - def process_query_property(self, query, paths): + def process_query_property(self, query, paths, mappers): if self.is_chained(): for path in paths: query._attributes[("loaderstrategy", path)] = self.get_strategy_class() diff --git a/lib/sqlalchemy/orm/strategies.py b/lib/sqlalchemy/orm/strategies.py index bdf99980c..c55d431f8 100644 --- a/lib/sqlalchemy/orm/strategies.py +++ b/lib/sqlalchemy/orm/strategies.py @@ -827,16 +827,17 @@ class LoadEagerFromAliasOption(PropertyOption): # dont run this option on a secondary load pass - def process_query_property(self, query, paths): + def process_query_property(self, query, paths, mappers): if self.alias: if isinstance(self.alias, basestring): - (mapper, propname) = paths[-1][-2:] - + mapper = mappers[-1] + (root_mapper, propname) = paths[-1][-2:] prop = mapper.get_property(propname, resolve_synonyms=True) self.alias = prop.target.alias(self.alias) query._attributes[("user_defined_eager_row_processor", paths[-1])] = sql_util.ColumnAdapter(self.alias) else: - (mapper, propname) = paths[-1][-2:] + (root_mapper, propname) = paths[-1][-2:] + mapper = mappers[-1] prop = mapper.get_property(propname, resolve_synonyms=True) adapter = query._polymorphic_adapters.get(prop.mapper, None) query._attributes[("user_defined_eager_row_processor", paths[-1])] = adapter |
