﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
584	[patch] fix many-to-many with non-default pks. 	rjwittams	Adrian Holovaty	"I found that many to many fields do not work when the primary keys of the objects are not default. 
As I'm working in the new-admin branch and this is an obvious fix, I thought I'd point it up here so
it can be applied to trunk. 

{{{
def method_set_related_many_to_many(rel_opts, rel_field, self, id_list):
    id_list = map(int, id_list) # normalize to integers
    rel = rel_field.rel.to
    m2m_table = rel_field.get_m2m_db_table(rel_opts)
    this_id = getattr(self, self._meta.pk.column)
    cursor = db.db.cursor()
    delete_stmt = ""DELETE FROM %s WHERE %s = %%s"" % (m2m_table, rel.pk.column)
    cursor.execute(delete_stmt, [this_id])
    insert_stmt = ""INSERT INTO %s (%s, %s) VALUES (%%s, %%s)"" % (m2m_table, rel.pk.column, rel_opts.pk.column)
    cursor.executemany(insert_stmt, [(this_id, i) for i in id_list])
    db.db.commit()
}}}"	defect	closed	Metasystem		major	duplicate			Unreviewed	1	0	0	0	0	0
