#NEWLINE# def _apply_joins( self , q , to_join , left_alias , parent_alias , effective_entity ) : #NEWLINE# #INDENT# for ( i , ( mapper , key ) ) in enumerate ( to_join ) : #NEWLINE# #INDENT# first = ( i == 0 ) #NEWLINE# middle = ( i < ( len ( to_join ) - 1 ) ) #NEWLINE# second_to_last = ( i == ( len ( to_join ) - 2 ) ) #NEWLINE# last = ( i == ( len ( to_join ) - 1 ) ) #NEWLINE# if first : #NEWLINE# #INDENT# attr = getattr ( left_alias , key ) #NEWLINE# if ( last and ( effective_entity is not self . mapper ) ) : #NEWLINE# #INDENT# attr = attr . of_type ( effective_entity ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# if ( last and ( effective_entity is not self . mapper ) ) : #NEWLINE# #INDENT# attr = getattr ( parent_alias , key ) . of_type ( effective_entity ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# attr = getattr ( mapper . entity , key ) #NEWLINE# #UNINDENT# #UNINDENT# if second_to_last : #NEWLINE# #INDENT# q = q . join ( parent_alias , attr , from_joinpoint = True ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# q = q . join ( attr , aliased = middle , from_joinpoint = True ) #NEWLINE# #UNINDENT# #UNINDENT# return q