mirror of https://github.com/django/django.git
Refs #35044 -- Added Model.refresh_from_db(fields=...) test for clearing reverse relations.
This commit is contained in:
parent
2d3531af23
commit
0c690c6001
|
@ -966,6 +966,13 @@ class ModelRefreshTests(TestCase):
|
||||||
article.refresh_from_db()
|
article.refresh_from_db()
|
||||||
self.assertTrue(hasattr(article, "featured"))
|
self.assertTrue(hasattr(article, "featured"))
|
||||||
|
|
||||||
|
def test_refresh_clears_reverse_related_explicit_fields(self):
|
||||||
|
article = Article.objects.create(headline="Test", pub_date=datetime(2024, 2, 4))
|
||||||
|
self.assertFalse(hasattr(article, "featured"))
|
||||||
|
FeaturedArticle.objects.create(article_id=article.pk)
|
||||||
|
article.refresh_from_db(fields=["featured"])
|
||||||
|
self.assertTrue(hasattr(article, "featured"))
|
||||||
|
|
||||||
def test_refresh_clears_one_to_one_field(self):
|
def test_refresh_clears_one_to_one_field(self):
|
||||||
article = Article.objects.create(
|
article = Article.objects.create(
|
||||||
headline="Parrot programs in Python",
|
headline="Parrot programs in Python",
|
||||||
|
|
Loading…
Reference in New Issue