@@ -1574,52 +1574,6 @@ def test_select_related_on_poly_classes_indirect_related(self):
15741574 self .assertIsInstance (obj_list [2 ].plainobj .relation , AltChildModel )
15751575 self .assertIsInstance (obj_list [3 ].plainobj .relation , AltChildModel )
15761576
1577- def test_select_related_on_poly_classes_indirect_related (self ):
1578- # can we fetch the related object but only the minimal 'common' values
1579- plain_a_obj_1 = PlainA .objects .create (field1 = "f1" )
1580- plain_a_obj_2 = PlainA .objects .create (field1 = "f2" )
1581- extra_obj = ModelExtraExternal .objects .create (topic = "t1" )
1582- obj_p = ParentModel .objects .create (name = "p1" )
1583- obj_c = ChildModel .objects .create (name = "c1" , other_name = "c1name" , link_on_child = extra_obj )
1584- obj_ac1 = AltChildModel .objects .create (
1585- name = "ac1" , other_name = "ac1name" , link_on_altchild = plain_a_obj_1
1586- )
1587- obj_ac2 = AltChildModel .objects .create (
1588- name = "ac2" , other_name = "ac2name" , link_on_altchild = plain_a_obj_2
1589- )
1590- obj_p_1 = PlainModel .objects .create (relation = obj_p )
1591- obj_p_2 = PlainModel .objects .create (relation = obj_c )
1592- obj_p_3 = PlainModel .objects .create (relation = obj_ac1 )
1593- obj_p_4 = PlainModel .objects .create (relation = obj_ac2 )
1594-
1595- robj_1 = RefPlainModel .objects .create (plainobj = obj_p_1 )
1596- robj_2 = RefPlainModel .objects .create (plainobj = obj_p_2 )
1597- robj_3 = RefPlainModel .objects .create (plainobj = obj_p_3 )
1598- robj_4 = RefPlainModel .objects .create (plainobj = obj_p_4 )
1599-
1600- # Prefetch content_types
1601- ContentType .objects .get_for_models (PlainModel , PlainA , ModelExtraExternal )
1602-
1603- with self .assertNumQueries (1 ):
1604- # pos 3 if i cannot do optimized select_related
1605- obj_list = list (
1606- RefPlainModel .poly_objects .select_related (
1607- # "plainobj__relation",
1608- "plainobj__relation" ,
1609- "plainobj__relation__ChildModel__link_on_child" ,
1610- "plainobj__relation__AltChildModel__link_on_altchild" ,
1611- ).order_by ("pk" )
1612- )
1613- with self .assertNumQueries (0 ):
1614- self .assertEqual (obj_list [0 ].plainobj .relation .name , "p1" )
1615- self .assertEqual (obj_list [1 ].plainobj .relation .name , "c1" )
1616- self .assertEqual (obj_list [2 ].plainobj .relation .name , "ac1" )
1617- self .assertEqual (obj_list [3 ].plainobj .relation .name , "ac2" )
1618-
1619- self .assertIsInstance (obj_list [0 ].plainobj .relation , ParentModel )
1620- self .assertIsInstance (obj_list [1 ].plainobj .relation , ChildModel )
1621- self .assertIsInstance (obj_list [2 ].plainobj .relation , AltChildModel )
1622- self .assertIsInstance (obj_list [3 ].plainobj .relation , AltChildModel )
16231577
16241578 def test_select_related_fecth_all_poly_classes_indirect_related (self ):
16251579 # can we fetch the related object but only the minimal 'common' values
0 commit comments