MultipleDatabaseSupport: naive-related.diff
File naive-related.diff, 2.4 KB (added by , 18 years ago) |
---|
-
related.py
old new 287 287 # Add the newly created or already existing objects to the join table. 288 288 # First find out which items are already added, to avoid adding them twice 289 289 new_ids = set([obj._get_pk_val() for obj in objs]) 290 cursor = connection.cursor()290 cursor = self.model._meta.connection.cursor() 291 291 cursor.execute("SELECT %s FROM %s WHERE %s = %%s AND %s IN (%s)" % \ 292 292 (target_col_name, self.join_table, source_col_name, 293 293 target_col_name, ",".join(['%s'] * len(new_ids))), … … 302 302 cursor.execute("INSERT INTO %s (%s, %s) VALUES (%%s, %%s)" % \ 303 303 (self.join_table, source_col_name, target_col_name), 304 304 [self._pk_val, obj_id]) 305 transaction.commit_unless_managed( )305 transaction.commit_unless_managed(self.model._meta.connection) 306 306 307 307 def _remove_items(self, source_col_name, target_col_name, *objs): 308 308 # source_col_name: the PK colname in join_table for the source object … … 314 314 if not isinstance(obj, self.model): 315 315 raise ValueError, "objects to remove() must be %s instances" % self.model._meta.object_name 316 316 # Remove the specified objects from the join table 317 cursor = connection.cursor()317 cursor = self.model._meta.connection.cursor() 318 318 for obj in objs: 319 319 cursor.execute("DELETE FROM %s WHERE %s = %%s AND %s = %%s" % \ 320 320 (self.join_table, source_col_name, target_col_name), 321 321 [self._pk_val, obj._get_pk_val()]) 322 transaction.commit_unless_managed( )322 transaction.commit_unless_managed(self.model._meta.connection) 323 323 324 324 def _clear_items(self, source_col_name): 325 325 # source_col_name: the PK colname in join_table for the source object 326 326 from django.db import connection 327 cursor = connection.cursor()327 cursor = self.model._meta.connection.cursor() 328 328 cursor.execute("DELETE FROM %s WHERE %s = %%s" % \ 329 329 (self.join_table, source_col_name), 330 330 [self._pk_val]) 331 transaction.commit_unless_managed( )331 transaction.commit_unless_managed(self.model._meta.connection) 332 332 333 333 return ManyRelatedManager 334 334