summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/mapping
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2006-02-16 06:13:16 +0000
committerMike Bayer <mike_mp@zzzcomputing.com>2006-02-16 06:13:16 +0000
commit52396072d0971086321d2908575a2e6b7d067ba3 (patch)
treeb86b119917fcd786ac3024c9c7b3ea7c73befe9c /lib/sqlalchemy/mapping
parent4d78d5f3ab1bc5b4d41f086fecc5acc36ead45af (diff)
downloadsqlalchemy-52396072d0971086321d2908575a2e6b7d067ba3.tar.gz
Join object wasnt exporting foreign keys correctly
compile_synchronizers in PropertyLoader needed to take into account the full list of tables for each mapper when looking for synchronization rules, not just primary table
Diffstat (limited to 'lib/sqlalchemy/mapping')
-rw-r--r--lib/sqlalchemy/mapping/properties.py32
1 files changed, 24 insertions, 8 deletions
diff --git a/lib/sqlalchemy/mapping/properties.py b/lib/sqlalchemy/mapping/properties.py
index 6edb15742..f686e588c 100644
--- a/lib/sqlalchemy/mapping/properties.py
+++ b/lib/sqlalchemy/mapping/properties.py
@@ -523,12 +523,23 @@ class PropertyLoader(MapperProperty):
SyncRule = PropertyLoader.SyncRule
+ parent_tables = util.HashSet(self.parent.tables + [self.parent.primarytable])
+ target_tables = util.HashSet(self.mapper.tables + [self.mapper.primarytable])
+
+ def check_for_table(binary, l):
+ for col in [binary.left, binary.right]:
+ if col.table in l:
+ return col
+ else:
+ return None
+
def compile(binary):
"""assembles a SyncRule given a single binary condition"""
if binary.operator != '=' or not isinstance(binary.left, schema.Column) or not isinstance(binary.right, schema.Column):
return
if binary.left.table == binary.right.table:
+ # self-cyclical relation
if binary.left.primary_key:
source = binary.left
dest = binary.right
@@ -544,18 +555,23 @@ class PropertyLoader(MapperProperty):
else:
raise "assert failed"
else:
- colmap = {binary.left.table : binary.left, binary.right.table : binary.right}
- if colmap.has_key(self.parent.primarytable) and colmap.has_key(self.target):
+ pt = check_for_table(binary, parent_tables)
+ tt = check_for_table(binary, target_tables)
+ st = check_for_table(binary, [self.secondary])
+ #print "parenttable", [t.name for t in parent_tables]
+ #print "ttable", [t.name for t in target_tables]
+ #print "OK", str(binary), pt, tt, st
+ if pt and tt:
if self.direction == PropertyLoader.ONETOMANY:
- self.syncrules.append(SyncRule(self.parent, colmap[self.parent.primarytable], colmap[self.target], dest_mapper=self.mapper))
+ self.syncrules.append(SyncRule(self.parent, pt, tt, dest_mapper=self.mapper))
elif self.direction == PropertyLoader.MANYTOONE:
- self.syncrules.append(SyncRule(self.mapper, colmap[self.target], colmap[self.parent.primarytable], dest_mapper=self.parent))
+ self.syncrules.append(SyncRule(self.mapper, tt, pt, dest_mapper=self.parent))
else:
raise "assert failed"
- elif colmap.has_key(self.parent.primarytable) and colmap.has_key(self.secondary):
- self.syncrules.append(SyncRule(self.parent, colmap[self.parent.primarytable], colmap[self.secondary], direction=PropertyLoader.ONETOMANY))
- elif colmap.has_key(self.target) and colmap.has_key(self.secondary):
- self.syncrules.append(SyncRule(self.mapper, colmap[self.target], colmap[self.secondary], direction=PropertyLoader.MANYTOONE))
+ elif pt and st:
+ self.syncrules.append(SyncRule(self.parent, pt, st, direction=PropertyLoader.ONETOMANY))
+ elif tt and st:
+ self.syncrules.append(SyncRule(self.mapper, tt, st, direction=PropertyLoader.MANYTOONE))
self.syncrules = []
processor = BinaryVisitor(compile)