summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2007-01-18 03:33:13 +0000
committerMike Bayer <mike_mp@zzzcomputing.com>2007-01-18 03:33:13 +0000
commitbfbf626317f8bb05fd19759f6d05f54fb7e2b3f9 (patch)
tree9f16bec93394587c9a95e3215fb4d40334abce52 /lib
parent1dd908c0972bac5248ac29adbf0816cb2a2d2bab (diff)
downloadsqlalchemy-bfbf626317f8bb05fd19759f6d05f54fb7e2b3f9.tar.gz
- some deeper error checking when compiling relations, to detect an ambiguous "primaryjoin"
in the case that both sides of the relationship have foreign key references in the primary join condition
Diffstat (limited to 'lib')
-rw-r--r--lib/sqlalchemy/orm/properties.py17
1 files changed, 11 insertions, 6 deletions
diff --git a/lib/sqlalchemy/orm/properties.py b/lib/sqlalchemy/orm/properties.py
index fc945fc72..ef7c82360 100644
--- a/lib/sqlalchemy/orm/properties.py
+++ b/lib/sqlalchemy/orm/properties.py
@@ -274,12 +274,17 @@ class PropertyLoader(StrategizedProperty):
return sync.ONETOMANY
else:
return sync.MANYTOONE
- elif len([c for c in self.foreignkey if self.mapper.unjoined_table.corresponding_column(c, False) is not None]):
- return sync.ONETOMANY
- elif len([c for c in self.foreignkey if self.parent.unjoined_table.corresponding_column(c, False) is not None]):
- return sync.MANYTOONE
else:
- raise exceptions.ArgumentError("Cant determine relation direction for '%s' in mapper '%s' with primary join\n '%s'" %(self.key, str(self.mapper), str(self.primaryjoin)))
+ onetomany = len([c for c in self.foreignkey if self.mapper.unjoined_table.corresponding_column(c, False) is not None])
+ manytoone = len([c for c in self.foreignkey if self.parent.unjoined_table.corresponding_column(c, False) is not None])
+ if not onetomany and not manytoone:
+ raise exceptions.ArgumentError("Cant determine relation direction for '%s' on mapper '%s' with primary join '%s' - foreign key columns are not present in neither the parent nor the child's mapped tables" %(self.key, str(self.parent), str(self.primaryjoin)))
+ elif onetomany and manytoone:
+ raise exceptions.ArgumentError("Cant determine relation direction for '%s' on mapper '%s' with primary join '%s' - foreign key columns are present in both the parent and the child's mapped tables. Specify 'foreignkey' argument." %(self.key, str(self.parent), str(self.primaryjoin)))
+ elif onetomany:
+ return sync.ONETOMANY
+ elif manytoone:
+ return sync.MANYTOONE
def _find_dependent(self):
"""searches through the primary join condition to determine which side
@@ -298,7 +303,7 @@ class PropertyLoader(StrategizedProperty):
visitor = mapperutil.BinaryVisitor(foo)
self.primaryjoin.accept_visitor(visitor)
if len(foreignkeys) == 0:
- raise exceptions.ArgumentError("On relation '%s', can't figure out which side is the foreign key for join condition '%s'. Specify the 'foreignkey' argument to the relation." % (self.key, str(self.primaryjoin)))
+ raise exceptions.ArgumentError("Cant determine relation direction for '%s' on mapper '%s' with primary join '%s' - no foreign key relationship is expressed within the join condition. Specify 'foreignkey' argument." %(self.key, str(self.parent), str(self.primaryjoin)))
self.foreignkey = foreignkeys
def get_join(self):