summaryrefslogtreecommitdiff
path: root/tests/invalid_models_tests
diff options
context:
space:
mode:
authorzeyneloz <ozdemir.zynl@gmail.com>2019-04-30 12:00:34 +0200
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2019-05-01 11:51:27 +0200
commit6485a5f450b3dc60e690c31a75e0e9574a896842 (patch)
tree41fb3099f5d257153dda9ce993cbe2d329aab49f /tests/invalid_models_tests
parent2106b983c433586925df12cdca72374829756e45 (diff)
Fixed #30409 -- Allowed using foreign key's attnames in unique/index_together and Index's fields.
Diffstat (limited to 'tests/invalid_models_tests')
-rw-r--r--tests/invalid_models_tests/test_models.py39
1 files changed, 39 insertions, 0 deletions
diff --git a/tests/invalid_models_tests/test_models.py b/tests/invalid_models_tests/test_models.py
index 6b57dd7d9d..32617555a2 100644
--- a/tests/invalid_models_tests/test_models.py
+++ b/tests/invalid_models_tests/test_models.py
@@ -117,6 +117,19 @@ class IndexTogetherTests(SimpleTestCase):
),
])
+ def test_pointing_to_fk(self):
+ class Foo(models.Model):
+ pass
+
+ class Bar(models.Model):
+ foo_1 = models.ForeignKey(Foo, on_delete=models.CASCADE, related_name='bar_1')
+ foo_2 = models.ForeignKey(Foo, on_delete=models.CASCADE, related_name='bar_2')
+
+ class Meta:
+ index_together = [['foo_1_id', 'foo_2']]
+
+ self.assertEqual(Bar.check(), [])
+
# unique_together tests are very similar to index_together tests.
@isolate_apps('invalid_models_tests')
@@ -204,6 +217,19 @@ class UniqueTogetherTests(SimpleTestCase):
),
])
+ def test_pointing_to_fk(self):
+ class Foo(models.Model):
+ pass
+
+ class Bar(models.Model):
+ foo_1 = models.ForeignKey(Foo, on_delete=models.CASCADE, related_name='bar_1')
+ foo_2 = models.ForeignKey(Foo, on_delete=models.CASCADE, related_name='bar_2')
+
+ class Meta:
+ unique_together = [['foo_1_id', 'foo_2']]
+
+ self.assertEqual(Bar.check(), [])
+
@isolate_apps('invalid_models_tests')
class IndexesTests(SimpleTestCase):
@@ -257,6 +283,19 @@ class IndexesTests(SimpleTestCase):
),
])
+ def test_pointing_to_fk(self):
+ class Foo(models.Model):
+ pass
+
+ class Bar(models.Model):
+ foo_1 = models.ForeignKey(Foo, on_delete=models.CASCADE, related_name='bar_1')
+ foo_2 = models.ForeignKey(Foo, on_delete=models.CASCADE, related_name='bar_2')
+
+ class Meta:
+ indexes = [models.Index(fields=['foo_1_id', 'foo_2'], name='index_name')]
+
+ self.assertEqual(Bar.check(), [])
+
@isolate_apps('invalid_models_tests')
class FieldNamesTests(SimpleTestCase):