diff --git a/tests/update/tests.py b/tests/update/tests.py
index abf4db11d9..e16084d896 100644
a
|
b
|
|
1 | 1 | from django.core.exceptions import FieldError |
2 | 2 | from django.db.models import Count, F, Max |
| 3 | from django.db.models.expressions import OuterRef, Subquery |
3 | 4 | from django.db.models.functions import Concat, Lower |
4 | 5 | from django.test import TestCase |
5 | 6 | |
6 | | from .models import A, B, Bar, D, DataPoint, Foo, RelatedPoint |
| 7 | from .models import A, B, Bar, C, D, DataPoint, Foo, RelatedPoint |
7 | 8 | |
8 | 9 | |
9 | 10 | class SimpleTest(TestCase): |
… |
… |
class AdvancedTests(TestCase):
|
199 | 200 | with self.subTest(annotation=annotation): |
200 | 201 | with self.assertRaisesMessage(FieldError, msg): |
201 | 202 | RelatedPoint.objects.annotate(new_name=annotation).update(name=F('new_name')) |
| 203 | |
| 204 | def test_update_with_joined_field_outerref(self): |
| 205 | a1 = A.objects.create(x=1) |
| 206 | a2 = A.objects.create(x=3) |
| 207 | a3 = A.objects.create(x=5) |
| 208 | B.objects.bulk_create([ |
| 209 | B(a=a1, y=1), |
| 210 | B(a=a2, y=3), |
| 211 | B(a=a3, y=4), |
| 212 | ]) |
| 213 | C.objects.bulk_create([ |
| 214 | C(y=5), |
| 215 | C(y=10), |
| 216 | C(y=15), |
| 217 | ]) |
| 218 | qs = C.objects.filter(y=OuterRef('a__x')) |
| 219 | B.objects.filter( |
| 220 | y__gt=3 |
| 221 | ).update(y=Subquery(qs.values('y')[:1])) |
| 222 | self.assertEqual(list(B.objects.filter(y__gt=3).values_list('y', flat=True)), [5]) |