#NEWLINE# def test_many_to_many_with_join( self ) : #NEWLINE# #INDENT# ( keywords , items , item_keywords , Keyword , Item ) = ( self . tables . keywords , self . tables . items , self . tables . item_keywords , self . classes . Keyword , self . classes . Item ) #NEWLINE# mapper ( Keyword , keywords ) #NEWLINE# mapper ( Item , items , properties = dict ( keywords = relationship ( Keyword , secondary = item_keywords , lazy = 'subquery' , order_by = keywords . c . id ) ) ) #NEWLINE# q = create_session ( ) . query ( Item ) . order_by ( Item . id ) #NEWLINE# def go( ) : #NEWLINE# #INDENT# eq_ ( self . static . item_keyword_result [ 0 : 2 ] , q . join ( 'keywords' ) . filter ( ( Keyword . name == 'red' ) ) . all ( ) ) #NEWLINE# #UNINDENT# self . assert_sql_count ( testing . db , go , 2 )