From 33abc55601107e9f12db3f0c16b3498b26c445f2 Mon Sep 17 00:00:00 2001 From: Hasan Ramezani Date: Tue, 13 Apr 2021 11:49:13 +0200 Subject: [PATCH] Refs #31530 -- Added test for joined OneToOneField in CheckConstraint.check --- tests/invalid_models_tests/test_models.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/tests/invalid_models_tests/test_models.py b/tests/invalid_models_tests/test_models.py index c79684487d..6c3017ff47 100644 --- a/tests/invalid_models_tests/test_models.py +++ b/tests/invalid_models_tests/test_models.py @@ -1778,6 +1778,7 @@ class ConstraintsTests(TestCase): field2 = models.PositiveSmallIntegerField() field3 = models.PositiveSmallIntegerField() parent = models.ForeignKey('self', models.CASCADE) + previous = models.OneToOneField('self', models.CASCADE, related_name='next') class Meta: constraints = [ @@ -1792,9 +1793,18 @@ class ConstraintsTests(TestCase): models.CheckConstraint( name='name3', check=models.Q(parent__field3=models.F('field1')) ), + models.CheckConstraint( + name='name4', check=models.Q(name=Lower('previous__name')), + ), ] - joined_fields = ['parent__field1', 'parent__field2', 'parent__field3', 'parent__name'] + joined_fields = [ + 'parent__field1', + 'parent__field2', + 'parent__field3', + 'parent__name', + 'previous__name', + ] errors = Model.check(databases=self.databases) expected_errors = [ Error(