mirror of
				https://github.com/django/django.git
				synced 2025-10-31 09:41:08 +00:00 
			
		
		
		
	Refs #28586 -- Copied fetch modes to related objects.
This change ensures that behavior and performance remain consistent when traversing relationships.
This commit is contained in:
		
				
					committed by
					
						 Jacob Walls
						Jacob Walls
					
				
			
			
				
	
			
			
			
						parent
						
							821619aa87
						
					
				
				
					commit
					6dc9b04018
				
			| @@ -7,6 +7,7 @@ from operator import attrgetter | ||||
| from unittest import expectedFailure | ||||
|  | ||||
| from django import forms | ||||
| from django.db.models import FETCH_PEERS | ||||
| from django.test import TestCase | ||||
|  | ||||
| from .models import ( | ||||
| @@ -600,6 +601,22 @@ class ModelInheritanceTest(TestCase): | ||||
|             self.assertEqual(restaurant.place_ptr.restaurant, restaurant) | ||||
|             self.assertEqual(restaurant.italianrestaurant, italian_restaurant) | ||||
|  | ||||
|     def test_parent_access_copies_fetch_mode(self): | ||||
|         italian_restaurant = ItalianRestaurant.objects.create( | ||||
|             name="Mom's Spaghetti", | ||||
|             address="2131 Woodward Ave", | ||||
|             serves_hot_dogs=False, | ||||
|             serves_pizza=False, | ||||
|             serves_gnocchi=True, | ||||
|         ) | ||||
|  | ||||
|         # No queries are made when accessing the parent objects. | ||||
|         italian_restaurant = ItalianRestaurant.objects.fetch_mode(FETCH_PEERS).get( | ||||
|             pk=italian_restaurant.pk | ||||
|         ) | ||||
|         restaurant = italian_restaurant.restaurant_ptr | ||||
|         self.assertEqual(restaurant._state.fetch_mode, FETCH_PEERS) | ||||
|  | ||||
|     def test_id_field_update_on_ancestor_change(self): | ||||
|         place1 = Place.objects.create(name="House of Pasta", address="944 Fullerton") | ||||
|         place2 = Place.objects.create(name="House of Pizza", address="954 Fullerton") | ||||
|   | ||||
		Reference in New Issue
	
	Block a user