#NEWLINE# def get_relation_count_query_for_self_join( self , query , parent ) : #NEWLINE# #INDENT# '\n        Add the constraints for a relationship count query on the same table.\n\n        :type query: orator.orm.Builder\n        :type parent: orator.orm.Builder\n\n        :rtype: orator.orm.Builder\n        ' #NEWLINE# query . select ( QueryExpression ( 'COUNT(*)' ) ) #NEWLINE# table_prefix = self . _query . get_query ( ) . get_connection ( ) . get_table_prefix ( ) #NEWLINE# hash_ = self . get_relation_count_hash ( ) #NEWLINE# query . from_ ( ( '%s AS %s%s' % ( self . _table , table_prefix , hash_ ) ) ) #NEWLINE# key = self . wrap ( self . get_qualified_parent_key_name ( ) ) #NEWLINE# return query . where ( ( '%s.%s' % ( hash_ , self . _foreign_key ) ) , '=' , QueryExpression ( key ) )