def METHOD_NAME(tables, papers):
    aggregated = []
    for paper in papers:
        paper_id = int(paper['_id'])
        relevant_tables = [t for t in tables
                           if t['_source']['related_publication'] == paper_id]
        # Create a function to extract table numbers from their DOIs.
        def sort_key(elem):
            """ Get the table number from the DOI. """
            try:
                table_num = int(elem['_source']['doi'].split('/')[-1].lstrip('t'))
            except (ValueError, AttributeError):  # this shouldn't happen
                table_num = 0
            return table_num
        # Sort the tables into the order they appear in the record.
        relevant_tables.sort(key=sort_key)
        aggregated.append((paper, relevant_tables))
    return aggregated