#NEWLINE# def test_regression_7110( self ) : #NEWLINE# #INDENT# '\n        Regression test for bug #7110.\n\n        When using select_related(), we must query the\n        Device and Building tables using two different aliases (each) in order to\n        differentiate the start and end Connection fields. The net result is that\n        both the "connections = ..." queries here should give the same results\n        without pulling in more than the absolute minimum number of tables\n        (history has shown that it\'s easy to make a mistake in the implementation\n        and include some unnecessary bonus joins).\n        ' #NEWLINE# b = Building . objects . create ( name = '101' ) #NEWLINE# dev1 = Device . objects . create ( name = 'router' , building = b ) #NEWLINE# dev2 = Device . objects . create ( name = 'switch' , building = b ) #NEWLINE# dev3 = Device . objects . create ( name = 'server' , building = b ) #NEWLINE# port1 = Port . objects . create ( port_number = '4' , device = dev1 ) #NEWLINE# port2 = Port . objects . create ( port_number = '7' , device = dev2 ) #NEWLINE# port3 = Port . objects . create ( port_number = '1' , device = dev3 ) #NEWLINE# c1 = Connection . objects . create ( start = port1 , end = port2 ) #NEWLINE# c2 = Connection . objects . create ( start = port2 , end = port3 ) #NEWLINE# connections = Connection . objects . filter ( start__device__building = b , end__device__building = b ) . order_by ( 'id' ) #NEWLINE# self . assertEqual ( [ ( c . id , unicode ( c . start ) , unicode ( port1 . end ) ) for c in connections ] , [ ( c1 . id , 'router/4' , 'switch/7' ) , ( c2 . id , 'switch/7' , 'server/1' ) ] ) #NEWLINE# connections = Connection . objects . filter ( start__device__building = b , end__device__building = b ) . select_related ( ) . order_by ( 'id' ) #NEWLINE# self . assertEqual ( [ ( c . id , unicode ( c . start ) , unicode ( c . end ) ) for c in connections ] , [ ( c1 . id , 'router/4' , 'switch/7' ) , ( c2 . id , 'switch/7' , 'server/1' ) ] ) #NEWLINE# self . assertEqual ( str ( connections . query ) . count ( ' JOIN ' ) , 6 )