Fixed #11107 -- Corrected the generation of sequence reset SQL for m2m fields with an intermediate model. Thanks to J Clifford Dyer for the report and fix.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@11215 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
55968a6edd
commit
52bc782621
1
AUTHORS
1
AUTHORS
|
@ -131,6 +131,7 @@ answer newbie questions, and generally made Django that much better:
|
||||||
Andrew Durdin <adurdin@gmail.com>
|
Andrew Durdin <adurdin@gmail.com>
|
||||||
dusk@woofle.net
|
dusk@woofle.net
|
||||||
Andy Dustman <farcepest@gmail.com>
|
Andy Dustman <farcepest@gmail.com>
|
||||||
|
J. Clifford Dyer <jcd@unc.edu>
|
||||||
Clint Ecker
|
Clint Ecker
|
||||||
Nick Efford <nick@efford.org>
|
Nick Efford <nick@efford.org>
|
||||||
eibaan@gmail.com
|
eibaan@gmail.com
|
||||||
|
|
|
@ -217,6 +217,7 @@ WHEN (new.%(col_name)s IS NULL)
|
||||||
# continue to loop
|
# continue to loop
|
||||||
break
|
break
|
||||||
for f in model._meta.many_to_many:
|
for f in model._meta.many_to_many:
|
||||||
|
if not f.rel.through:
|
||||||
table_name = self.quote_name(f.m2m_db_table())
|
table_name = self.quote_name(f.m2m_db_table())
|
||||||
sequence_name = get_sequence_name(f.m2m_db_table())
|
sequence_name = get_sequence_name(f.m2m_db_table())
|
||||||
column_name = self.quote_name('id')
|
column_name = self.quote_name('id')
|
||||||
|
|
|
@ -121,6 +121,7 @@ class DatabaseOperations(BaseDatabaseOperations):
|
||||||
style.SQL_TABLE(qn(model._meta.db_table))))
|
style.SQL_TABLE(qn(model._meta.db_table))))
|
||||||
break # Only one AutoField is allowed per model, so don't bother continuing.
|
break # Only one AutoField is allowed per model, so don't bother continuing.
|
||||||
for f in model._meta.many_to_many:
|
for f in model._meta.many_to_many:
|
||||||
|
if not f.rel.through:
|
||||||
output.append("%s setval('%s', coalesce(max(%s), 1), max(%s) %s null) %s %s;" % \
|
output.append("%s setval('%s', coalesce(max(%s), 1), max(%s) %s null) %s %s;" % \
|
||||||
(style.SQL_KEYWORD('SELECT'),
|
(style.SQL_KEYWORD('SELECT'),
|
||||||
style.SQL_FIELD(qn('%s_id_seq' % f.m2m_db_table())),
|
style.SQL_FIELD(qn('%s_id_seq' % f.m2m_db_table())),
|
||||||
|
|
|
@ -0,0 +1,34 @@
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"pk": "1",
|
||||||
|
"model": "m2m_through_regress.person",
|
||||||
|
"fields": {
|
||||||
|
"name": "Guido"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"pk": "1",
|
||||||
|
"model": "auth.user",
|
||||||
|
"fields": {
|
||||||
|
"username": "Guido",
|
||||||
|
"email": "bdfl@python.org",
|
||||||
|
"password": "abcde"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"pk": "1",
|
||||||
|
"model": "m2m_through_regress.group",
|
||||||
|
"fields": {
|
||||||
|
"name": "Python Core Group"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"pk": "1",
|
||||||
|
"model": "m2m_through_regress.usermembership",
|
||||||
|
"fields": {
|
||||||
|
"user": "1",
|
||||||
|
"group": "1",
|
||||||
|
"price": "100"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
|
@ -12,7 +12,9 @@ class Membership(models.Model):
|
||||||
def __unicode__(self):
|
def __unicode__(self):
|
||||||
return "%s is a member of %s" % (self.person.name, self.group.name)
|
return "%s is a member of %s" % (self.person.name, self.group.name)
|
||||||
|
|
||||||
|
# using custom id column to test ticket #11107
|
||||||
class UserMembership(models.Model):
|
class UserMembership(models.Model):
|
||||||
|
id = models.AutoField(db_column='usermembership_id', primary_key=True)
|
||||||
user = models.ForeignKey(User)
|
user = models.ForeignKey(User)
|
||||||
group = models.ForeignKey('Group')
|
group = models.ForeignKey('Group')
|
||||||
price = models.IntegerField(default=100)
|
price = models.IntegerField(default=100)
|
||||||
|
@ -196,4 +198,12 @@ doing a join.
|
||||||
# Flush the database, just to make sure we can.
|
# Flush the database, just to make sure we can.
|
||||||
>>> management.call_command('flush', verbosity=0, interactive=False)
|
>>> management.call_command('flush', verbosity=0, interactive=False)
|
||||||
|
|
||||||
|
## Regression test for #11107
|
||||||
|
Ensure that sequences on m2m_through tables are being created for the through
|
||||||
|
model, not for a phantom auto-generated m2m table.
|
||||||
|
|
||||||
|
>>> management.call_command('loaddata', 'm2m_through', verbosity=0)
|
||||||
|
>>> management.call_command('dumpdata', 'm2m_through_regress', format='json')
|
||||||
|
[{"pk": 1, "model": "m2m_through_regress.usermembership", "fields": {"price": 100, "group": 1, "user": 1}}, {"pk": 1, "model": "m2m_through_regress.person", "fields": {"name": "Guido"}}, {"pk": 1, "model": "m2m_through_regress.group", "fields": {"name": "Python Core Group"}}]
|
||||||
|
|
||||||
"""}
|
"""}
|
||||||
|
|
Loading…
Reference in New Issue