Skip to content

Commit 743976e

Browse files
migeed-zfacebook-github-bot
authored andcommitted
Test disabled reverse relations
Summary: We can use the "+" symbol to avoid creating a reverse relation. This is important to test so we can make sure we are avoiding creating that field if it is not needed Reviewed By: aleivag, yangdanny97 Differential Revision: D90517596
1 parent 93ace9b commit 743976e

1 file changed

Lines changed: 18 additions & 0 deletions

File tree

pyrefly/lib/test/django/reverse_relations.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,21 @@ author = Author()
4242
author.written_books # E: `Author` has no attribute `written_books`
4343
"#,
4444
);
45+
46+
django_testcase!(
47+
test_foreign_key_reverse_disabled,
48+
r#"
49+
from django.db import models
50+
51+
class Author(models.Model):
52+
name = models.CharField(max_length=100)
53+
54+
class Book(models.Model):
55+
# related_name='+' disables the reverse accessor entirely
56+
author = models.ForeignKey(Author, on_delete=models.CASCADE, related_name='+')
57+
58+
author = Author()
59+
# No reverse accessor should exist
60+
author.book_set # E: `Author` has no attribute `book_set`
61+
"#,
62+
);

0 commit comments

Comments
 (0)