#NEWLINE# def test_mixin_attr_refers_to_column_copies( self ) : #NEWLINE# #INDENT# counter = mock . Mock ( ) #NEWLINE# class HasAddressCount ( object ) : #NEWLINE# #INDENT# id = Column ( Integer , primary_key = True ) #NEWLINE# @ declared_attr #NEWLINE# def address_count( cls ) : #NEWLINE# #INDENT# counter ( cls . id ) #NEWLINE# return column_property ( select ( [ func . count ( Address . id ) ] ) . where ( ( Address . user_id == cls . id ) ) . as_scalar ( ) ) #NEWLINE# #UNINDENT# #UNINDENT# class Address ( Base ) : #NEWLINE# #INDENT# __tablename__ = 'address' #NEWLINE# id = Column ( Integer , primary_key = True ) #NEWLINE# user_id = Column ( ForeignKey ( 'user.id' ) ) #NEWLINE# #UNINDENT# class User ( Base , HasAddressCount ) : #NEWLINE# #INDENT# __tablename__ = 'user' #NEWLINE# #UNINDENT# eq_ ( sess . mock_calls , [ mock . call ( User . id ) ] ) #NEWLINE# sess = Session ( ) #NEWLINE# self . assert_compile ( sess . query ( User ) . having ( ( User . address_count > 5 ) ) , 'SELECT (SELECT count(address.id) AS count_1 FROM address WHERE address.user_id = "user".id) AS anon_1, "user".id AS user_id FROM "user" HAVING (SELECT count(address.id) AS count_1 FROM address WHERE address.user_id = "user".id) > :param_1' )