Ticket #11107: many_to_many.rel.through.5.diff
File many_to_many.rel.through.5.diff, 5.3 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/fixtures/m2m_through.json
1 [ 2 { 3 "pk": "1", 4 "model": "m2m_through_regress.person", 5 "fields": { 6 "name": "Guido" 7 } 8 }, 9 { 10 "pk": "1", 11 "model": "auth.user", 12 "fields": { 13 "username": "Guido", 14 "email": "bdfl@python.org", 15 "password": "abcde" 16 } 17 }, 18 { 19 "pk": "1", 20 "model": "m2m_through_regress.group", 21 "fields": { 22 "name": "Python Core Group" 23 } 24 }, 25 { 26 "pk": "1", 27 "model": "m2m_through_regress.usermembership", 28 "fields": { 29 "user": "1", 30 "group": "1", 31 "price": "100" 32 } 33 } 34 ] 35 No newline at end of file -
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('loaddata', 'm2m_through', verbosity=0) 206 199 207 """} -
docs/ref/django-admin.txt
611 611 612 612 Prints the SQL statements for resetting sequences for the given app name(s). 613 613 614 See http://simon .incutio.com/archive/2004/04/21/postgresfor more information.614 See http://simonwillison.net/2004/Apr/21/postgres/ for more information. 615 615 616 616 startapp <appname> 617 617 ------------------