def search_relationship(session, instance, relation, filters=None, sort=None, group_by=None):
 model = get_model(instance)
 related_model = get_related_model(model, relation)
 query = session_query(session, related_model)
 relationship = getattr(instance, relation)
 primary_keys = set((primary_key_value(inst) for inst in relationship))
 if (not primary_keys):
  return query.filter(FALSE())
 query = query.filter(primary_key_value(related_model).in_(primary_keys))
 return search(session, related_model, filters=filters, sort=sort, group_by=group_by, _initial_query=query)

def search_relationship ( session , instance , relation , filters = None , sort = None , group_by = None ) : model = get_model ( instance ) related_model = get_related_model ( model , relation ) query = session_query ( session , related_model ) relationship = getattr ( instance , relation ) primary_keys = set ( ( primary_key_value ( inst ) for inst in relationship ) ) if ( not primary_keys ) : return query . filter ( FALSE ( ) ) query = query . filter ( primary_key_value ( related_model ) . in_ ( primary_keys ) ) return search ( session , related_model , filters = filters , sort = sort , group_by = group_by , _initial_query = query )
returns a filtered .