diff options
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/filtered_relation/tests.py | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/tests/filtered_relation/tests.py b/tests/filtered_relation/tests.py index 0fce8b092a..2cceeb82e7 100644 --- a/tests/filtered_relation/tests.py +++ b/tests/filtered_relation/tests.py @@ -793,6 +793,47 @@ class FilteredRelationAggregationTests(TestCase): qs.annotate(total=Count("pk")).values("total"), [{"total": 1}] ) + def test_condition_spans_join(self): + self.assertSequenceEqual( + Book.objects.annotate( + contains_editor_author=FilteredRelation( + "author", condition=Q(author__name__icontains=F("editor__name")) + ) + ).filter( + contains_editor_author__isnull=False, + ), + [self.book1], + ) + + def test_condition_spans_join_chained(self): + self.assertSequenceEqual( + Book.objects.annotate( + contains_editor_author=FilteredRelation( + "author", condition=Q(author__name__icontains=F("editor__name")) + ), + contains_editor_author_ref=FilteredRelation( + "author", + condition=Q(author__name=F("contains_editor_author__name")), + ), + ).filter( + contains_editor_author_ref__isnull=False, + ), + [self.book1], + ) + + def test_condition_self_ref(self): + self.assertSequenceEqual( + Book.objects.annotate( + contains_author=FilteredRelation( + "author", + condition=Q(title__icontains=F("author__name")), + ) + ).filter( + contains_author__isnull=False, + ), + [self.book1], + ) + class FilteredRelationAnalyticalAggregationTests(TestCase): @classmethod |
