diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2013-04-25 13:54:40 -0400 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2013-04-25 13:54:40 -0400 |
commit | 6f05aa06bfde7a9aa1437fa542232bf05ff13df2 (patch) | |
tree | de79cb1b694625174a4ab8935ffaff3186c6fc01 /lib/sqlalchemy | |
parent | 637232709770de034caf67c9ece6121c83c43681 (diff) | |
download | sqlalchemy-6f05aa06bfde7a9aa1437fa542232bf05ff13df2.tar.gz |
everything passes with this!!!!!!! holy crap !!!!! and its the simplest of all
Diffstat (limited to 'lib/sqlalchemy')
-rw-r--r-- | lib/sqlalchemy/orm/util.py | 126 | ||||
-rw-r--r-- | lib/sqlalchemy/sql/expression.py | 16 | ||||
-rw-r--r-- | lib/sqlalchemy/sql/util.py | 2 |
3 files changed, 84 insertions, 60 deletions
diff --git a/lib/sqlalchemy/orm/util.py b/lib/sqlalchemy/orm/util.py index dd24d8bf4..9472f8698 100644 --- a/lib/sqlalchemy/orm/util.py +++ b/lib/sqlalchemy/orm/util.py @@ -874,70 +874,82 @@ class _ORMJoin(expression.Join): isouter=False, join_to_left=True): adapt_from = None - if hasattr(left, '_orm_mappers'): - left_mapper = left._orm_mappers[1] - else: - info = inspection.inspect(left) - left_mapper = getattr(info, 'mapper', None) - left_info = inspection.inspect(left) - left_selectable = left_info.selectable - info = inspection.inspect(right) - right_mapper = getattr(info, 'mapper', None) - right = info.selectable - right_is_aliased = getattr(info, 'is_aliased_class', False) + if hasattr(left, '_orm_infos'): + left_orm_info = left._orm_infos[1] + else: + #if isinstance(left, expression.Join): + # info = inspection.inspect(left.right) + #else: + # info = inspection.inspect(left) + left_orm_info = left_info - if right_is_aliased: - adapt_to = right + right_info = inspection.inspect(right) + + if getattr(right_info, 'is_aliased_class', False): + adapt_to = right_info.selectable else: adapt_to = None - if left_mapper or right_mapper: - self._orm_mappers = (left_mapper, right_mapper) - - if isinstance(onclause, basestring): - prop = left_mapper.get_property(onclause) - on_selectable = prop.parent.selectable - elif isinstance(onclause, attributes.QueryableAttribute): - on_selectable = onclause.comparator._source_selectable() - #if adapt_from is None: - # adapt_from = onclause.comparator._source_selectable() - prop = onclause.property - elif isinstance(onclause, MapperProperty): - prop = onclause - on_selectable = prop.parent.selectable +# import pdb +# pdb.set_trace() + self._orm_infos = (left_orm_info, right_info) + + if isinstance(onclause, basestring): + onclause = getattr(left_orm_info.entity, onclause) + + if isinstance(onclause, attributes.QueryableAttribute): + on_selectable = onclause.comparator._source_selectable() + prop = onclause.property + elif isinstance(onclause, MapperProperty): + prop = onclause + on_selectable = prop.parent.selectable + else: + prop = None + + if prop: + #import pdb + #pdb.set_trace() + if sql_util.clause_is_present(on_selectable, left_info.selectable): + adapt_from = on_selectable + else: + adapt_from = left_info.selectable +# import pdb +# pdb.set_trace() + #adapt_from = left_orm_info.selectable + #adapt_from = left_info.selectable +# adapt_from = None +# if adapt_from is None: +# _derived = [] +# for s in expression._from_objects(left_info.selectable): +# if s == on_selectable: +# adapt_from = s +# break +# elif s.is_derived_from(on_selectable): +# _derived.append(s) +# else: +# if _derived: +# adapt_from = _derived[0] + + #if adapt_from is None: +# adapt_from = left_info.selectable + + #adapt_from = None + pj, sj, source, dest, \ + secondary, target_adapter = prop._create_joins( + source_selectable=adapt_from, + dest_selectable=adapt_to, + source_polymorphic=True, + dest_polymorphic=True, + of_type=right_info.mapper) + + if sj is not None: + left = sql.join(left, secondary, pj, isouter) + onclause = sj else: - prop = None - - if prop: - import pdb - pdb.set_trace() - _derived = [] - for s in expression._from_objects(left_selectable): - if s == on_selectable: - adapt_from = s - break - elif s.is_derived_from(on_selectable): - _derived.append(s) - else: - if _derived: - adapt_from = _derived[0] - - pj, sj, source, dest, \ - secondary, target_adapter = prop._create_joins( - source_selectable=adapt_from, - dest_selectable=adapt_to, - source_polymorphic=True, - dest_polymorphic=True, - of_type=right_mapper) - - if sj is not None: - left = sql.join(left, secondary, pj, isouter) - onclause = sj - else: - onclause = pj - self._target_adapter = target_adapter + onclause = pj + self._target_adapter = target_adapter expression.Join.__init__(self, left, right, onclause, isouter) diff --git a/lib/sqlalchemy/sql/expression.py b/lib/sqlalchemy/sql/expression.py index d2e644ce2..92b8aea98 100644 --- a/lib/sqlalchemy/sql/expression.py +++ b/lib/sqlalchemy/sql/expression.py @@ -3909,8 +3909,14 @@ class Join(FromClause): def is_derived_from(self, fromclause): return fromclause is self or \ - self.left.is_derived_from(fromclause) or\ - self.right.is_derived_from(fromclause) + self.left.is_derived_from(fromclause) or \ + self.right.is_derived_from(fromclause) or \ + ( + isinstance(fromclause, Join) and + self.left.is_derived_from(fromclause.left) and + self.right.is_derived_from(fromclause.right) and + self.onclause.compare(fromclause.onclause) + ) def self_group(self, against=None): return FromGrouping(self) @@ -3947,6 +3953,12 @@ class Join(FromClause): def get_children(self, **kwargs): return self.left, self.right, self.onclause + def compare(self, other): + return isinstance(other, Join) and \ + self.left.compare(other.left) and \ + self.right.compare(other.right) and \ + self.onclause.compare(other.onclause) + def _match_primaries(self, left, right): if isinstance(left, Join): left_right = left.right diff --git a/lib/sqlalchemy/sql/util.py b/lib/sqlalchemy/sql/util.py index 520c90f99..4aa2d7496 100644 --- a/lib/sqlalchemy/sql/util.py +++ b/lib/sqlalchemy/sql/util.py @@ -203,7 +203,7 @@ def clause_is_present(clause, search): stack = [search] while stack: elem = stack.pop() - if clause is elem: + if clause == elem: # use == here so that Annotated's compare return True elif isinstance(elem, expression.Join): stack.extend((elem.left, elem.right)) |