diff options
| author | Mike Bayer <mike_mp@zzzcomputing.com> | 2013-04-24 18:58:09 -0400 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2013-04-24 18:58:09 -0400 |
| commit | 637232709770de034caf67c9ece6121c83c43681 (patch) | |
| tree | 0945fdf7d21eb15f8210a9d4345348c8c0b69c2e /lib/sqlalchemy/orm/util.py | |
| parent | c3c9a3f701921875710a727362a57a0b50bf1a53 (diff) | |
| download | sqlalchemy-637232709770de034caf67c9ece6121c83c43681.tar.gz | |
- attempt to replace the whole idea of "join_to_left" with a more
fundamental and general purpose heuristic. this initial approach
has about 60 tests failing but seems to have gone pretty far
Diffstat (limited to 'lib/sqlalchemy/orm/util.py')
| -rw-r--r-- | lib/sqlalchemy/orm/util.py | 32 |
1 files changed, 22 insertions, 10 deletions
diff --git a/lib/sqlalchemy/orm/util.py b/lib/sqlalchemy/orm/util.py index f3b8e271d..dd24d8bf4 100644 --- a/lib/sqlalchemy/orm/util.py +++ b/lib/sqlalchemy/orm/util.py @@ -872,20 +872,16 @@ class _ORMJoin(expression.Join): def __init__(self, left, right, onclause=None, isouter=False, join_to_left=True): - adapt_from = None + adapt_from = None if hasattr(left, '_orm_mappers'): left_mapper = left._orm_mappers[1] - if join_to_left: - adapt_from = left.right else: info = inspection.inspect(left) left_mapper = getattr(info, 'mapper', None) - left = info.selectable - left_is_aliased = getattr(info, 'is_aliased_class', False) - if join_to_left and (left_is_aliased or not left_mapper): - adapt_from = left + left_info = inspection.inspect(left) + left_selectable = left_info.selectable info = inspection.inspect(right) right_mapper = getattr(info, 'mapper', None) @@ -902,18 +898,34 @@ class _ORMJoin(expression.Join): if isinstance(onclause, basestring): prop = left_mapper.get_property(onclause) + on_selectable = prop.parent.selectable elif isinstance(onclause, attributes.QueryableAttribute): - if adapt_from is None: - adapt_from = onclause.comparator._source_selectable() + 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 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( + secondary, target_adapter = prop._create_joins( source_selectable=adapt_from, dest_selectable=adapt_to, source_polymorphic=True, |
