#NEWLINE# def test_join_pk_collapse_explicit( self ) : #NEWLINE# #INDENT# "test that redundant columns in a join get 'collapsed' into a\n        minimal primary key, which is the root column along a chain of\n        explicit join conditions." #NEWLINE# meta = MetaData ( ) #NEWLINE# a = Table ( 'a' , meta , Column ( 'id' , Integer , primary_key = True ) , Column ( 'x' , Integer ) ) #NEWLINE# b = Table ( 'b' , meta , Column ( 'id' , Integer , ForeignKey ( 'a.id' ) , primary_key = True ) , Column ( 'x' , Integer ) ) #NEWLINE# c = Table ( 'c' , meta , Column ( 'id' , Integer , ForeignKey ( 'b.id' ) , primary_key = True ) , Column ( 'x' , Integer ) ) #NEWLINE# d = Table ( 'd' , meta , Column ( 'id' , Integer , ForeignKey ( 'c.id' ) , primary_key = True ) , Column ( 'x' , Integer ) ) #NEWLINE# print ( list ( a . join ( b , ( a . c . x == b . c . id ) ) . primary_key ) ) #NEWLINE# assert ( list ( a . join ( b , ( a . c . x == b . c . id ) ) . primary_key ) == [ a . c . id ] ) #NEWLINE# assert ( list ( b . join ( c , ( b . c . x == c . c . id ) ) . primary_key ) == [ b . c . id ] ) #NEWLINE# assert ( list ( a . join ( b ) . join ( c , ( c . c . id == b . c . x ) ) . primary_key ) == [ a . c . id ] ) #NEWLINE# assert ( list ( b . join ( c , ( c . c . x == b . c . id ) ) . join ( d ) . primary_key ) == [ b . c . id ] ) #NEWLINE# assert ( list ( b . join ( c , ( c . c . id == b . c . x ) ) . join ( d ) . primary_key ) == [ b . c . id ] ) #NEWLINE# assert ( list ( d . join ( b , ( d . c . id == b . c . id ) ) . join ( c , ( b . c . id == c . c . x ) ) . primary_key ) == [ b . c . id ] ) #NEWLINE# assert ( list ( a . join ( b ) . join ( c , ( c . c . id == b . c . x ) ) . join ( d ) . primary_key ) == [ a . c . id ] ) #NEWLINE# assert ( list ( a . join ( b , and_ ( ( a . c . id == b . c . id ) , ( a . c . x == b . c . id ) ) ) . primary_key ) == [ self . c . id ] )