'Makes sure the given \'model\' is joined in the query. If \'model\' isn\'t
a parent of \'opts\' or if it is None this method is a no-op.
The \'alias\' is the root alias for starting the join, \'seen\' is a dict
of model -> alias of existing joins. It must also contain a mapping
of None -> some alias. This will be returned in the no-op case.'

def join_parent_model(self, opts, model, alias, seen):

    if (model in seen):
        return seen[model]
    chain = opts.get_base_chain(model)
    if (chain is None):
        return alias
    curr_opts = opts
    for int_model in chain:
        if (int_model in seen):
            return seen[int_model]
        if (not curr_opts.parents[int_model]):
            curr_opts = int_model._meta
            continue
        link_field = curr_opts.get_ancestor_link(int_model)
        (_, _, _, joins, _) = self.setup_joins([link_field.name], curr_opts, alias)
        curr_opts = int_model._meta
        alias = seen[int_model] = joins[(-1)]
    return (alias or seen[None])
