#NEWLINE# def trim_joins( self , targets , joins , path ) : #NEWLINE# #INDENT# "\n        The 'target' parameter is the final field being joined to, 'joins'\n        is the full list of join aliases. The 'path' contain the PathInfos\n        used to create the joins.\n\n        Returns the final target field and table alias and the new active\n        joins.\n\n        We will always trim any direct join if we have the target column\n        available already in the previous table. Reverse joins can't be\n        trimmed as we don't know if there is anything on the other side of\n        the join.\n        " #NEWLINE# joins = joins [ : ] #NEWLINE# for ( pos , info ) in enumerate ( reversed ( path ) ) : #NEWLINE# #INDENT# if ( ( len ( joins ) == 1 ) or ( not info . direct ) ) : #NEWLINE# #INDENT# break #NEWLINE# #UNINDENT# join_targets = set ( ( t . column for t in info . join_field . foreign_related_fields ) ) #NEWLINE# cur_targets = set ( ( t . column for t in targets ) ) #NEWLINE# if ( not cur_targets . issubset ( join_targets ) ) : #NEWLINE# #INDENT# break #NEWLINE# #UNINDENT# targets = tuple ( ( r [ 0 ] for r in info . join_field . related_fields if ( r [ 1 ] . column in cur_targets ) ) ) #NEWLINE# self . unref_alias ( joins . pop ( ) ) #NEWLINE# #UNINDENT# return ( targets , joins [ ( - 1 ) ] , joins )