summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/sql/util.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2012-02-25 17:10:06 -0500
committerMike Bayer <mike_mp@zzzcomputing.com>2012-02-25 17:10:06 -0500
commitd37320306560c3d758ed65563d53aa9500095a49 (patch)
tree59523646cf9622394ff2b321d9a661f8f50dffad /lib/sqlalchemy/sql/util.py
parentd934ea23e24880a5c784c9e5edf9ead5bc965a83 (diff)
downloadsqlalchemy-d37320306560c3d758ed65563d53aa9500095a49.tar.gz
start to work on error messages, allow foreign_keys as only argument
if otherwise can't determine join condition due to no fks
Diffstat (limited to 'lib/sqlalchemy/sql/util.py')
-rw-r--r--lib/sqlalchemy/sql/util.py14
1 files changed, 11 insertions, 3 deletions
diff --git a/lib/sqlalchemy/sql/util.py b/lib/sqlalchemy/sql/util.py
index 2862e9af9..38d95dde5 100644
--- a/lib/sqlalchemy/sql/util.py
+++ b/lib/sqlalchemy/sql/util.py
@@ -284,8 +284,10 @@ def adapt_criterion_to_null(crit, nulls):
return visitors.cloned_traverse(crit, {}, {'binary':visit_binary})
+
def join_condition(a, b, ignore_nonexistent_tables=False,
- a_subset=None):
+ a_subset=None,
+ consider_as_foreign_keys=None):
"""create a join condition between two tables or selectables.
e.g.::
@@ -321,6 +323,9 @@ def join_condition(a, b, ignore_nonexistent_tables=False,
for fk in sorted(
b.foreign_keys,
key=lambda fk:fk.parent._creation_order):
+ if consider_as_foreign_keys is not None and \
+ fk.parent not in consider_as_foreign_keys:
+ continue
try:
col = fk.get_referent(left)
except exc.NoReferenceError, nrte:
@@ -336,6 +341,9 @@ def join_condition(a, b, ignore_nonexistent_tables=False,
for fk in sorted(
left.foreign_keys,
key=lambda fk:fk.parent._creation_order):
+ if consider_as_foreign_keys is not None and \
+ fk.parent not in consider_as_foreign_keys:
+ continue
try:
col = fk.get_referent(b)
except exc.NoReferenceError, nrte:
@@ -358,11 +366,11 @@ def join_condition(a, b, ignore_nonexistent_tables=False,
"subquery using alias()?"
else:
hint = ""
- raise exc.ArgumentError(
+ raise exc.NoForeignKeysError(
"Can't find any foreign key relationships "
"between '%s' and '%s'.%s" % (a.description, b.description, hint))
elif len(constraints) > 1:
- raise exc.ArgumentError(
+ raise exc.AmbiguousForeignKeysError(
"Can't determine join between '%s' and '%s'; "
"tables have more than one foreign key "
"constraint relationship between them. "