def map_nested_attrs(nested_dict, split_attr_name, query_data):
    """
    A function that can be called recursively to map attributes from related
    entities to the associated data

    :param nested_dict: Dictionary to insert data into
    :type nested_dict: :class:`dict`
    :param split_attr_name: List of parts to an attribute name, that have been split
        by "."
    :type split_attr_name: :class:`list`
    :param query_data: Data to be added to the dictionary
    :type query_data: :class:`str` or :class:`str`
    :return: Dictionary to be added to the result dictionary
    """
    # Popping LHS of related attribute name to see if it's an attribute name or part
    # of a path to a related entity
    attr_name_pop = split_attr_name.pop(0)

    # Related attribute name, ready to insert data into dictionary
    if len(split_attr_name) == 0:
        # at role, so put data in
        nested_dict[attr_name_pop] = query_data
    # Part of the path for related entity, need to recurse to get to attribute name
    else:
        nested_dict[attr_name_pop] = {}
        map_nested_attrs(nested_dict[attr_name_pop], split_attr_name, query_data)

    return nested_dict