def _get_fk_relations_helper(unvisited_tables, visited_tables,
                             fk_relations_map):
  """Returns a ForeignKeyRelation connecting to an unvisited table, or None."""
  for table_to_visit in unvisited_tables:
    for table in visited_tables:
      if (table, table_to_visit) in fk_relations_map:
        fk_relation = fk_relations_map[(table, table_to_visit)]
        unvisited_tables.remove(table_to_visit)
        visited_tables.append(table_to_visit)
        return fk_relation
  return None