def _add_approx_entity_index_var(es, target_entity_id, cutoffs, path):
    """
    Add a variable to the cutoff df linking it to the entity at the end of the
    path.

    Return the updated cutoff df and the name of this variable. The name will
    consist of the variables which were joined through.
    """
    last_child_var = 'instance_id'
    last_parent_var = es[target_entity_id].index
    for _, relationship in path:
        child_vars = [last_parent_var, relationship.child_variable.id]
        child_df = es[relationship.child_entity.id].df[child_vars]
        new_var_name = '%s.%s' % (last_child_var, relationship.
            child_variable.id)
        to_rename = {relationship.child_variable.id: new_var_name}
        child_df = child_df.rename(columns=to_rename)
        cutoffs = cutoffs.merge(child_df, left_on=last_child_var, right_on=
            last_parent_var)
        last_child_var = new_var_name
        last_parent_var = relationship.parent_variable.id
    return cutoffs, new_var_name
