Ticket #11107: many_to_many.rel.through.4.diff
File many_to_many.rel.through.4.diff, 4.8 KB (added by , 16 years ago) |
---|
-
django/db/backends/postgresql/operations.py
121 121 style.SQL_TABLE(qn(model._meta.db_table)))) 122 122 break # Only one AutoField is allowed per model, so don't bother continuing. 123 123 for f in model._meta.many_to_many: 124 output.append("%s setval('%s', coalesce(max(%s), 1), max(%s) %s null) %s %s;" % \ 125 (style.SQL_KEYWORD('SELECT'), 126 style.SQL_FIELD(qn('%s_id_seq' % f.m2m_db_table())), 127 style.SQL_FIELD(qn('id')), 128 style.SQL_FIELD(qn('id')), 129 style.SQL_KEYWORD('IS NOT'), 130 style.SQL_KEYWORD('FROM'), 131 style.SQL_TABLE(qn(f.m2m_db_table())))) 124 if not f.rel.through: 125 output.append("%s setval('%s', coalesce(max(%s), 1), max(%s) %s null) %s %s;" % \ 126 (style.SQL_KEYWORD('SELECT'), 127 style.SQL_FIELD(qn('%s_id_seq' % f.m2m_db_table())), 128 style.SQL_FIELD(qn('id')), 129 style.SQL_FIELD(qn('id')), 130 style.SQL_KEYWORD('IS NOT'), 131 style.SQL_KEYWORD('FROM'), 132 style.SQL_TABLE(qn(f.m2m_db_table())))) 132 133 return output 133 134 134 135 def savepoint_create_sql(self, sid): -
django/db/backends/oracle/base.py
217 217 # continue to loop 218 218 break 219 219 for f in model._meta.many_to_many: 220 table_name = self.quote_name(f.m2m_db_table()) 221 sequence_name = get_sequence_name(f.m2m_db_table()) 222 column_name = self.quote_name('id') 223 output.append(query % {'sequence': sequence_name, 224 'table': table_name, 225 'column': column_name}) 220 if not f.rel.through: 221 table_name = self.quote_name(f.m2m_db_table()) 222 sequence_name = get_sequence_name(f.m2m_db_table()) 223 column_name = self.quote_name('id') 224 output.append(query % {'sequence': sequence_name, 225 'table': table_name, 226 'column': column_name}) 226 227 return output 227 228 228 229 def start_transaction_sql(self): -
tests/regressiontests/m2m_through_regress/models.py
12 12 def __unicode__(self): 13 13 return "%s is a member of %s" % (self.person.name, self.group.name) 14 14 15 # using custom id column to test ticket #11107 15 16 class UserMembership(models.Model): 17 id = models.AutoField(db_column='usermembership_id', primary_key=True) 16 18 user = models.ForeignKey(User) 17 19 group = models.ForeignKey('Group') 18 20 price = models.IntegerField(default=100) … … 196 198 # Flush the database, just to make sure we can. 197 199 >>> management.call_command('flush', verbosity=0, interactive=False) 198 200 201 ## Regression test for #11107 202 Ensure that sequences on m2m_through tables are being created for the through 203 model, not for a phantom auto-generated m2m table. 204 205 >>> management.call_command('sqlsequencereset', 'm2m_through_regress') 206 BEGIN; 207 SELECT setval('"m2m_through_regress_membership_id_seq"', coalesce(max("id"), 1), max("id") IS NOT null) FROM "m2m_through_regress_membership"; 208 SELECT setval('"m2m_through_regress_usermembership_usermembership_id_seq"', coalesce(max("usermembership_id"), 1), max("usermembership_id") IS NOT null) FROM "m2m_through_regress_usermembership"; 209 SELECT setval('"m2m_through_regress_person_id_seq"', coalesce(max("id"), 1), max("id") IS NOT null) FROM "m2m_through_regress_person"; 210 SELECT setval('"m2m_through_regress_group_id_seq"', coalesce(max("id"), 1), max("id") IS NOT null) FROM "m2m_through_regress_group"; 211 SELECT setval('"m2m_through_regress_a_id_seq"', coalesce(max("id"), 1), max("id") IS NOT null) FROM "m2m_through_regress_a"; 212 SELECT setval('"m2m_through_regress_throughbase_id_seq"', coalesce(max("id"), 1), max("id") IS NOT null) FROM "m2m_through_regress_throughbase"; 213 SELECT setval('"m2m_through_regress_b_id_seq"', coalesce(max("id"), 1), max("id") IS NOT null) FROM "m2m_through_regress_b"; 214 COMMIT; 199 215 """}