]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
(no commit message)
authorMike Bayer <mike_mp@zzzcomputing.com>
Thu, 15 Sep 2005 04:06:09 +0000 (04:06 +0000)
committerMike Bayer <mike_mp@zzzcomputing.com>
Thu, 15 Sep 2005 04:06:09 +0000 (04:06 +0000)
lib/sqlalchemy/mapper.py
lib/sqlalchemy/objectstore.py

index 910823afd7f5ed5d741c278189a235be7cf7a986..808a6391461836ce8d5d82cb6eab8594ace19f1a 100644 (file)
@@ -175,7 +175,7 @@ class Mapper(object):
         except KeyError:
             clause = sql.and_()
             i = 0
-            for primary_key in self.primary_keys[table]:
+            for primary_key in self.primary_keys[self.table]:
                 # appending to the and_'s clause list directly to skip
                 # typechecks etc.
                 clause.clauses.append(primary_key == ident[i])
@@ -237,14 +237,15 @@ class Mapper(object):
             work[table] = {'insert': [], 'update': []}
                 
         for obj in objects:
-            params = {}
-            for col in table.columns:
-                params[col.key] = self._getattrbycolumn(obj, col)
-                
-            if hasattr(obj, "_instance_key"):
-                work[table]['update'].append(params)
-            else:
-                work[table]['insert'].append((obj, params))
+            for table in self.tables:
+                params = {}
+                for col in table.columns:
+                    params[col.key] = self._getattrbycolumn(obj, col)
+
+                if hasattr(obj, "_instance_key"):
+                    work[table]['update'].append(params)
+                else:
+                    work[table]['insert'].append((obj, params))
 
         for table, stuff in work.iteritems():
             if len(stuff['update']):
@@ -417,7 +418,7 @@ class PropertyLoader(MapperProperty):
         self.key = key
         self.parent = parent
         
-        # if join conditions were not specified, figure them out based on primary keys
+        # if join conditions were not specified, figure them out based on foreign keys
         if self.secondary is not None:
             if self.secondaryjoin is None:
                 self.secondaryjoin = self.match_primaries(self.target, self.secondary)
@@ -430,15 +431,15 @@ class PropertyLoader(MapperProperty):
         # if the foreign key wasnt specified and theres no assocaition table, try to figure
         # out who is dependent on who. we dont need all the foreign keys represented in the join,
         # just one of them.  
-#        if self.foreignkey is None and self.secondaryjoin is None:
+        if self.foreignkey is None and self.secondaryjoin is None:
             # else we usually will have a one-to-many where the secondary depends on the primary
             # but its possible that its reversed
-#            w = PropertyLoader.FindDependent()
-#            self.primaryjoin.accept_visitor(w)
-#            if w.dependent is None:
-#                raise "cant determine primary foreign key in the join relationship....specify foreignkey=<column>"
-#            else:
-#                self.foreignkey = w.dependent
+            w = PropertyLoader.FindDependent()
+            self.primaryjoin.accept_visitor(w)
+            if w.dependent is None:
+                raise "cant determine primary foreign key in the join relationship....specify foreignkey=<column>"
+            else:
+                self.foreignkey = w.dependent
                 
         if not hasattr(parent.class_, key):
             setattr(parent.class_, key, SmartProperty(key).property(usehistory = True, uselist = self.uselist))
index aefd9812309fb7b8d49a56b16d00d97874f7842d..cd6cbb9bf88cfdb64ac44327e1d01ba024df31dc 100644 (file)
@@ -37,7 +37,7 @@ def get_id_key(ident, class_, table):
     return value: a tuple object which is used as an identity key.
     """
     return (class_, table, tuple(ident))
-def get_instance_key(object, class_, table, primary_keys):
+def get_instance_key(object, class_, table, primary_keys, mapper):
     """returns an identity-map key for use in storing/retrieving an item from the identity map, given
     the object instance itself.
     
@@ -49,7 +49,8 @@ def get_instance_key(object, class_, table, primary_keys):
     may be synonymous with the table argument or can be a larger construct containing that table.
     return value: a tuple object which is used as an identity key.
     """
-    return (class_, table, tuple([getattr(object, column.key, None) for column in primary_keys]))
+    # TODO: clean this up, too many args, too confusing
+    return (class_, table, tuple([mapper._getattrbycolumn(object, column) for column in primary_keys]))
 def get_row_key(row, class_, table, primary_keys):
     """returns an identity-map key for use in storing/retrieving an item from the identity map, given
     a result set row.
@@ -74,7 +75,6 @@ def get(key):
         return val
     
 def put(key, obj, scope='thread'):
-
     if isinstance(obj, dict):
         raise "cant put a dict in the object store"