| 1051 | def test_join_promotion_with_multiple_annotations(self): |
| 1052 | o = CaseTestModel.objects.create(integer=1, integer2=1, string='1') |
| 1053 | # Testing that: |
| 1054 | # 1. There isn't any object on the remote side of the fk_rel |
| 1055 | # relation. If the query used inner joins, then the join to fk_rel |
| 1056 | # would remove o from the results. So, in effect we are testing that |
| 1057 | # we are promoting the fk_rel join to a left outer join here. |
| 1058 | # 2. The default value of 3 is generated for the case expression. |
| 1059 | self.assertQuerysetEqual( |
| 1060 | CaseTestModel.objects.filter(pk=o.pk).annotate( |
| 1061 | foo=Case( |
| 1062 | When(fk_rel__pk=1, then=2), |
| 1063 | default=3, |
| 1064 | output_field=models.IntegerField() |
| 1065 | ), |
| 1066 | bar=Case( |
| 1067 | When(fk_rel__pk=1, then=4), |
| 1068 | default=5, |
| 1069 | output_field=models.IntegerField() |
| 1070 | ), |
| 1071 | ), |
| 1072 | [(o, 3, 5)], |
| 1073 | lambda x: (x, x.foo, x.bar) |
| 1074 | ) |
| 1075 | # Now 2 should be generated, as the fk_rel is null. |
| 1076 | self.assertQuerysetEqual( |
| 1077 | CaseTestModel.objects.filter(pk=o.pk).annotate( |
| 1078 | foo=Case( |
| 1079 | When(fk_rel__isnull=True, then=2), |
| 1080 | default=3, |
| 1081 | output_field=models.IntegerField() |
| 1082 | ), |
| 1083 | bar=Case( |
| 1084 | When(fk_rel__isnull=True, then=4), |
| 1085 | default=5, |
| 1086 | output_field=models.IntegerField() |
| 1087 | ), |
| 1088 | ), |
| 1089 | [(o, 2, 4)], |
| 1090 | lambda x: (x, x.foo, x.bar) |
| 1091 | ) |
| 1092 | |