mirror of
				https://github.com/django/django.git
				synced 2025-10-31 09:41:08 +00:00 
			
		
		
		
	Added test to demonstrate issue 11387 isn't there anymore.
Thanks adurdin for the report and patch. Fixes #11387.
This commit is contained in:
		| @@ -2,7 +2,7 @@ from django.db.models import Q | ||||
| from django.test import TestCase | ||||
|  | ||||
| from .models import (Address, Place, Restaurant, Link, CharLink, TextLink, | ||||
|     Person, Contact, Note, Organization, OddRelation1, OddRelation2) | ||||
|     Person, Contact, Note, Organization, OddRelation1, OddRelation2, Company) | ||||
|  | ||||
|  | ||||
| class GenericRelationTests(TestCase): | ||||
| @@ -80,3 +80,21 @@ class GenericRelationTests(TestCase): | ||||
|         ) | ||||
|         self.assertEqual(str(qs.query).count('JOIN'), 2) | ||||
|  | ||||
|     def test_generic_relation_ordering(self): | ||||
|         """ | ||||
|         Test that ordering over a generic relation does not include extraneous | ||||
|         duplicate results, nor excludes rows not participating in the relation. | ||||
|         """ | ||||
|         p1 = Place.objects.create(name="South Park") | ||||
|         p2 = Place.objects.create(name="The City") | ||||
|         c = Company.objects.create(name="Chubby's Intl.") | ||||
|         l1 = Link.objects.create(content_object=p1) | ||||
|         l2 = Link.objects.create(content_object=c) | ||||
|  | ||||
|         places = list(Place.objects.order_by('links__id')) | ||||
|         def count_places(place): | ||||
|             return len(filter(lambda p: p.id == place.id, places)) | ||||
|  | ||||
|         self.assertEqual(len(places), 2) | ||||
|         self.assertEqual(count_places(p1), 1) | ||||
|         self.assertEqual(count_places(p2), 1) | ||||
|   | ||||
		Reference in New Issue
	
	Block a user