#NEWLINE# def test_relationship( self ) : #NEWLINE# #INDENT# class SomeRelated ( self . Base , ComparableEntity ) : #NEWLINE# #INDENT# __tablename__ = 'somerelated' #NEWLINE# id = Column ( Integer , primary_key = True ) #NEWLINE# #UNINDENT# class SomeClass ( Versioned , self . Base , ComparableEntity ) : #NEWLINE# #INDENT# __tablename__ = 'sometable' #NEWLINE# id = Column ( Integer , primary_key = True ) #NEWLINE# name = Column ( String ( 50 ) ) #NEWLINE# related_id = Column ( Integer , ForeignKey ( 'somerelated.id' ) ) #NEWLINE# related = relationship ( 'SomeRelated' , backref = 'classes' ) #NEWLINE# #UNINDENT# SomeClassHistory = SomeClass . __history_mapper__ . class_ #NEWLINE# self . create_tables ( ) #NEWLINE# sess = self . session #NEWLINE# sc = SomeClass ( name = 'sc1' ) #NEWLINE# sess . add ( sc ) #NEWLINE# sess . commit ( ) #NEWLINE# assert ( sc . version == 1 ) #NEWLINE# sr1 = SomeRelated ( ) #NEWLINE# sc . related = sr1 #NEWLINE# sess . commit ( ) #NEWLINE# assert ( sc . version == 2 ) #NEWLINE# eq_ ( sess . query ( SomeClassHistory ) . filter ( ( SomeClassHistory . version == 1 ) ) . all ( ) , [ SomeClassHistory ( version = 1 , name = 'sc1' , related_id = None ) ] ) #NEWLINE# sc . related = None #NEWLINE# eq_ ( sess . query ( SomeClassHistory ) . order_by ( SomeClassHistory . version ) . all ( ) , [ SomeClassHistory ( version = 1 , name = 'sc1' , related_id = None ) , SomeClassHistory ( version = 2 , name = 'sc1' , related_id = sess . id ) ] ) #NEWLINE# assert ( sc . version == 3 )