#NEWLINE# def test_double( self ) : #NEWLINE# #INDENT# 'Eager loading with two relationships simultaneously,\n            from the same table, using aliases.' #NEWLINE# ( users , orders , User , Address , Order , addresses ) = ( self . tables . users , self . tables . orders , self . classes . User , self . classes . Address , self . classes . Order , self . tables . addresses ) #NEWLINE# openorders = sa . alias ( orders , 'openorders' ) #NEWLINE# closedorders = sa . alias ( orders , 'closedorders' ) #NEWLINE# mapper ( Address , addresses ) #NEWLINE# mapper ( Order , orders ) #NEWLINE# open_mapper = mapper ( Order , openorders , non_primary = True ) #NEWLINE# closed_mapper = mapper ( Order , closedorders , non_primary = True ) #NEWLINE# mapper ( User , users , properties = dict ( addresses = relationship ( Address , lazy = 'subquery' , order_by = addresses . c . id ) , open_orders = relationship ( open_mapper , primaryjoin = sa . and_ ( ( openorders . c . isopen == 1 ) , ( users . c . id == openorders . c . user_id ) ) , lazy = 'subquery' , order_by = openorders . c . id ) , closed_orders = relationship ( closed_mapper , primaryjoin = sa . and_ ( ( closedorders . c . isopen == 0 ) , ( users . c . id == closedorders . c . user_id ) ) , lazy = 'subquery' , order_by = closedorders . c . id ) ) ) #NEWLINE# q = create_session ( ) . query ( User ) . order_by ( User . id ) #NEWLINE# def go( ) : #NEWLINE# #INDENT# eq_ ( [ User ( id = 7 , addresses = [ Address ( id = 1 ) ] , open_orders = [ Order ( id = 3 ) ] , closed_orders = [ Order ( id = 1 ) , Order ( id = 5 ) ] ) , User ( id = 8 , addresses = [ Address ( id = 2 ) , Address ( id = 3 ) , Address ( id = 4 ) ] , open_orders = [ ] , closed_orders = [ ] ) , User ( id = 9 , addresses = [ Address ( id = 5 ) ] , open_orders = [ Order ( id = 4 ) ] , closed_orders = [ Order ( id = 2 ) ] ) , User ( id = 10 ) ] , q . all ( ) ) #NEWLINE# #UNINDENT# self . assert_sql_count ( testing . db , go , 4 )