summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/sql/expression.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2008-05-02 01:02:23 +0000
committerMike Bayer <mike_mp@zzzcomputing.com>2008-05-02 01:02:23 +0000
commite3460573d037e27592995277a19840be13457828 (patch)
tree90fbd43479edb50e2cdc12f40fa90bc5368ed846 /lib/sqlalchemy/sql/expression.py
parentc407a608c38a8d483e77fb950b21995b16fa05f7 (diff)
downloadsqlalchemy-e3460573d037e27592995277a19840be13457828.tar.gz
- factored out the logic used by Join to create its join condition
- With declarative, joined table inheritance mappers use a slightly relaxed function to create the "inherit condition" to the parent table, so that other foreign keys to not-yet-declared Table objects don't trigger an error.
Diffstat (limited to 'lib/sqlalchemy/sql/expression.py')
-rw-r--r--lib/sqlalchemy/sql/expression.py32
1 files changed, 4 insertions, 28 deletions
diff --git a/lib/sqlalchemy/sql/expression.py b/lib/sqlalchemy/sql/expression.py
index 94c145613..1143bf8aa 100644
--- a/lib/sqlalchemy/sql/expression.py
+++ b/lib/sqlalchemy/sql/expression.py
@@ -2308,34 +2308,10 @@ class Join(FromClause):
return self.left, self.right, self.onclause
def __match_primaries(self, primary, secondary):
- crit = []
- constraints = util.Set()
- for fk in secondary.foreign_keys:
- col = fk.get_referent(primary)
- if col:
- crit.append(col == fk.parent)
- constraints.add(fk.constraint)
- if primary is not secondary:
- for fk in primary.foreign_keys:
- col = fk.get_referent(secondary)
- if col:
- crit.append(col == fk.parent)
- constraints.add(fk.constraint)
- if len(crit) == 0:
- raise exceptions.ArgumentError(
- "Can't find any foreign key relationships "
- "between '%s' and '%s'" % (primary.description, secondary.description))
- elif len(constraints) > 1:
- raise exceptions.ArgumentError(
- "Can't determine join between '%s' and '%s'; "
- "tables have more than one foreign key "
- "constraint relationship between them. "
- "Please specify the 'onclause' of this "
- "join explicitly." % (primary.description, secondary.description))
- elif len(crit) == 1:
- return (crit[0])
- else:
- return and_(*crit)
+ global sql_util
+ if not sql_util:
+ from sqlalchemy.sql import util as sql_util
+ return sql_util.join_condition(primary, secondary)
def select(self, whereclause=None, fold_equivalents=False, **kwargs):
"""Create a ``Select`` from this ``Join``.