mirror of
https://github.com/django/django.git
synced 2025-08-04 02:48:35 +00:00
Fixed #29118 -- Fixed crash with QuerySet.order_by(Exists(...)).
This commit is contained in:
parent
1a1264f149
commit
bf26f66029
3 changed files with 14 additions and 6 deletions
|
@ -38,10 +38,8 @@ class BasicExpressionsTests(TestCase):
|
|||
name="Foobar Ltd.", num_employees=3, num_chairs=4,
|
||||
ceo=Employee.objects.create(firstname="Frank", lastname="Meyer", salary=20)
|
||||
)
|
||||
cls.gmbh = Company.objects.create(
|
||||
name="Test GmbH", num_employees=32, num_chairs=1,
|
||||
ceo=Employee.objects.create(firstname="Max", lastname="Mustermann", salary=30)
|
||||
)
|
||||
cls.max = Employee.objects.create(firstname='Max', lastname='Mustermann', salary=30)
|
||||
cls.gmbh = Company.objects.create(name='Test GmbH', num_employees=32, num_chairs=1, ceo=cls.max)
|
||||
|
||||
def setUp(self):
|
||||
self.company_query = Company.objects.values(
|
||||
|
@ -399,6 +397,14 @@ class BasicExpressionsTests(TestCase):
|
|||
)
|
||||
self.assertEqual(str(qs.query).count('JOIN'), 2)
|
||||
|
||||
def test_order_by_exists(self):
|
||||
mary = Employee.objects.create(firstname='Mary', lastname='Mustermann', salary=20)
|
||||
mustermanns_by_seniority = Employee.objects.filter(lastname='Mustermann').order_by(
|
||||
# Order by whether the employee is the CEO of a company
|
||||
Exists(Company.objects.filter(ceo=OuterRef('pk'))).desc()
|
||||
)
|
||||
self.assertSequenceEqual(mustermanns_by_seniority, [self.max, mary])
|
||||
|
||||
def test_outerref(self):
|
||||
inner = Company.objects.filter(point_of_contact=OuterRef('pk'))
|
||||
msg = (
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue