Refs #22875 -- Fixed an optimizer test to use a valid scenario.

An explicit intermediary many-to-many relationship must declare forward and
reverse foreign keys. The original issue was in the autodetector as these
operations shouldn't have been generated in this order in the first place
which is tested by AutodetectorTests.test_create_with_through_model.
This commit is contained in:
Simon Charette 2017-01-30 14:14:38 -05:00 committed by Tim Graham
parent 263e039411
commit e4c0878b30
1 changed files with 9 additions and 5 deletions

View File

@ -318,14 +318,18 @@ class OptimizerTests(SimpleTestCase):
AddField should NOT optimize into CreateModel if it's an M2M using a AddField should NOT optimize into CreateModel if it's an M2M using a
through that's created between them. through that's created between them.
""" """
# Note: The middle model is not actually a valid through model,
# but that doesn't matter, as we never render it.
self.assertDoesNotOptimize( self.assertDoesNotOptimize(
[ [
migrations.CreateModel("Foo", [("name", models.CharField(max_length=255))]), migrations.CreateModel('Employee', []),
migrations.CreateModel("LinkThrough", []), migrations.CreateModel('Employer', []),
migrations.CreateModel('Employment', [
('employee', models.ForeignKey('migrations.Employee', models.CASCADE)),
('employment', models.ForeignKey('migrations.Employer', models.CASCADE)),
]),
migrations.AddField( migrations.AddField(
"Foo", "link", models.ManyToManyField("migrations.Link", through="migrations.LinkThrough") 'Employer', 'employees', models.ManyToManyField(
'migrations.Employee', through='migrations.Employment',
)
), ),
], ],
) )