#NEWLINE# def test_belongs_to_many_further_query( self ) : #NEWLINE# #INDENT# user = OratorTestUser . create ( id = 1 , email = 'john@doe.com' ) #NEWLINE# friend = OratorTestUser . create ( id = 2 , email = 'jane@doe.com' ) #NEWLINE# another_friend = OratorTestUser . create ( id = 3 , email = 'another@doe.com' ) #NEWLINE# user . friends ( ) . attach ( self ) #NEWLINE# user . friends ( ) . attach ( another_friend ) #NEWLINE# related_friend = OratorTestUser . with_ ( 'friends' ) . find ( 1 ) . friends ( ) . where ( 'test_users.id' , 3 ) . first ( ) #NEWLINE# self . assertEqual ( 3 , related_friend . id ) #NEWLINE# self . assertEqual ( 'another@doe.com' , related_friend . email ) #NEWLINE# self . assertIn ( 'pivot' , related_friend . to_dict ( ) ) #NEWLINE# self . assertEqual ( 1 , related_friend . pivot . user_id ) #NEWLINE# self . assertEqual ( 3 , related_friend . pivot . friend_id ) #NEWLINE# self . assertTrue ( hasattr ( related_friend . pivot , 'id' ) ) #NEWLINE# self . assertIsInstance ( user . friends ( ) . with_pivot ( 'id' ) , BelongsToMany )