diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2009-03-15 03:02:42 +0000 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2009-03-15 03:02:42 +0000 |
commit | 53deb98918263cd0a89d1a0aeb73f7010d8907bf (patch) | |
tree | 5bac2e7f91bd78cc14140f8e1443a88392d3ddb2 /lib/sqlalchemy/sql/util.py | |
parent | 3f0252abc77399b20ab263c70d5ec328c405c525 (diff) | |
download | sqlalchemy-53deb98918263cd0a89d1a0aeb73f7010d8907bf.tar.gz |
- Query.join() can now construct multiple FROM clauses, if
needed. Such as, query(A, B).join(A.x).join(B.y)
might say SELECT A.*, B.* FROM A JOIN X, B JOIN Y.
Eager loading can also tack its joins onto those
multiple FROM clauses. [ticket:1337]
Diffstat (limited to 'lib/sqlalchemy/sql/util.py')
-rw-r--r-- | lib/sqlalchemy/sql/util.py | 32 |
1 files changed, 24 insertions, 8 deletions
diff --git a/lib/sqlalchemy/sql/util.py b/lib/sqlalchemy/sql/util.py index b8ceabb74..a8de5c635 100644 --- a/lib/sqlalchemy/sql/util.py +++ b/lib/sqlalchemy/sql/util.py @@ -21,15 +21,31 @@ def sort_tables(tables): visitors.traverse(table, {'schema_visitor':True}, {'foreign_key':visit_foreign_key}) return topological.sort(tuples, tables) -def search(clause, target): - if not clause: - return False - for elem in visitors.iterate(clause, {'column_collections':False}): - if elem is target: - return True +def find_join_source(clauses, join_to): + """Given a list of FROM clauses and a selectable, + return the first index and element from the list of + clauses which can be joined against the selectable. returns + None, None if no match is found. + + e.g.:: + + clause1 = table1.join(table2) + clause2 = table4.join(table5) + + join_to = table2.join(table3) + + find_join_source([clause1, clause2], join_to) == clause1 + + """ + + selectables = list(expression._from_objects(join_to)) + for i, f in enumerate(clauses): + for s in selectables: + if f.is_derived_from(s): + return i, f else: - return False - + return None, None + def find_tables(clause, check_columns=False, include_aliases=False, include_joins=False, include_selects=False): """locate Table objects within the given expression.""" |