diff --git a/tests/modeltests/many_to_one/models.py b/tests/modeltests/many_to_one/models.py
index 53ad446..e79a894 100644
a
|
b
|
class Article(models.Model):
|
25 | 25 | class Meta: |
26 | 26 | ordering = ('headline',) |
27 | 27 | |
| 28 | class Category(models.Model): |
| 29 | name = models.CharField(max_length=20) |
| 30 | |
| 31 | class Record(models.Model): |
| 32 | category = models.ForeignKey(Category) |
| 33 | |
| 34 | class Relation(models.Model): |
| 35 | left = models.ForeignKey(Record, related_name='left_set') |
| 36 | right = models.ForeignKey(Record, related_name='right_set') |
| 37 | |
28 | 38 | __test__ = {'API_TESTS':""" |
29 | 39 | # Create a few Reporters. |
30 | 40 | >>> r = Reporter(first_name='John', last_name='Smith', email='john@example.com') |
… |
… |
True
|
286 | 296 | [datetime.datetime(1980, 4, 1, 0, 0)] |
287 | 297 | >>> Article.objects.select_related().dates('pub_date', 'year') |
288 | 298 | [datetime.datetime(1980, 1, 1, 0, 0)] |
| 299 | |
| 300 | # Test of multiple ForeignKeys to the same model |
| 301 | # Add some categories/records/relations |
| 302 | |
| 303 | >>> c1 = Category.objects.create(name='First') |
| 304 | >>> c2 = Category.objects.create(name='Second') |
| 305 | >>> r1 = Record.objects.create(category=c1) |
| 306 | >>> r2 = Record.objects.create(category=c1) |
| 307 | >>> r3 = Record.objects.create(category=c2) |
| 308 | >>> r4 = Record.objects.create(category=c2) |
| 309 | >>> r = Relation.objects.create(left=r1, right=r2) |
| 310 | >>> r = Relation.objects.create(left=r3, right=r4) |
| 311 | >>> r = Relation.objects.create(left=r1, right=r3) |
| 312 | |
| 313 | # Yields wrong sql |
| 314 | >>> Relation.objects.filter(left__category__name__in=['Second'], right__category__name__in=['First']).query.as_sql() |
| 315 | ('SELECT "many_to_one_relation"."id", "many_to_one_relation"."left_id", "many_to_one_relation"."right_id" FROM "many_to_one_relation" INNER JOIN "many_to_one_record" ON ("many_to_one_relation"."right_id" = "many_to_one_record"."id") INNER JOIN "many_to_one_category" ON ("many_to_one_record"."category_id" = "many_to_one_category"."id") INNER JOIN "many_to_one_record" T4 ON ("many_to_one_relation"."left_id" = T4."id") INNER JOIN "many_to_one_record" T5 ON ("many_to_one_relation"."right_id" = T5."id") WHERE T5."name" IN (%s) AND T4."name" IN (%s)', ('First', 'Second')) |
289 | 316 | """} |