--- related.py.orig	2006-06-20 22:34:33.000000000 -0700
+++ related.py	2006-06-20 22:38:29.000000000 -0700
@@ -287,7 +287,7 @@
             # Add the newly created or already existing objects to the join table.
             # First find out which items are already added, to avoid adding them twice
             new_ids = set([obj._get_pk_val() for obj in objs])
-            cursor = connection.cursor()
+            cursor = self.model._meta.connection.cursor()
             cursor.execute("SELECT %s FROM %s WHERE %s = %%s AND %s IN (%s)" % \
                 (target_col_name, self.join_table, source_col_name,
                 target_col_name, ",".join(['%s'] * len(new_ids))),
@@ -302,7 +302,7 @@
                 cursor.execute("INSERT INTO %s (%s, %s) VALUES (%%s, %%s)" % \
                     (self.join_table, source_col_name, target_col_name),
                     [self._pk_val, obj_id])
-            transaction.commit_unless_managed()
+            transaction.commit_unless_managed(self.model._meta.connection)
 
         def _remove_items(self, source_col_name, target_col_name, *objs):
             # source_col_name: the PK colname in join_table for the source object
@@ -314,21 +314,21 @@
                 if not isinstance(obj, self.model):
                     raise ValueError, "objects to remove() must be %s instances" % self.model._meta.object_name
             # Remove the specified objects from the join table
-            cursor = connection.cursor()
+            cursor = self.model._meta.connection.cursor()
             for obj in objs:
                 cursor.execute("DELETE FROM %s WHERE %s = %%s AND %s = %%s" % \
                     (self.join_table, source_col_name, target_col_name),
                     [self._pk_val, obj._get_pk_val()])
-            transaction.commit_unless_managed()
+            transaction.commit_unless_managed(self.model._meta.connection)
 
         def _clear_items(self, source_col_name):
             # source_col_name: the PK colname in join_table for the source object
             from django.db import connection
-            cursor = connection.cursor()
+            cursor = self.model._meta.connection.cursor()
             cursor.execute("DELETE FROM %s WHERE %s = %%s" % \
                 (self.join_table, source_col_name),
                 [self._pk_val])
-            transaction.commit_unless_managed()
+            transaction.commit_unless_managed(self.model._meta.connection)
 
     return ManyRelatedManager
 
