import json


def get_foreign_key_relash_from_pkg(pkg_json):
    """Generate a dictionary of foreign key relationships from pkging metadata.

    This function helps us pull all of the foreign key relationships of all
    of the tables in the metadata.

    Args:
        datapackage_json_path (path-like): Path to the datapackage.json
            containing the schema from which the foreign key relationships
            will be read

    Returns:
        dict: list of foreign key tables

    """
    with open(pkg_json) as md:
        metadata = json.load(md)

    fk_relash = {}
    for tbl in metadata['resources']:
        fk_relash[tbl['name']] = []
        if 'foreignKeys' in tbl['schema']:
            fk_tables = []
            for fk in tbl['schema']['foreignKeys']:
                fk_tables.append(fk['reference']['resource'])
            fk_relash[tbl['name']] = fk_tables
    return(fk_relash)