'Find a component alias from the link table alias.
@param tablename: the name of the master table
@param link: the alias of the link table'

@classmethod
def get_alias(cls, tablename, link):

    components = current.model.components
    table = cls.table(tablename)
    if (not table):
        return None
    def get_alias(hooks, link):
        if (link[(-6):] == '__link'):
            alias = link.rsplit('__link', 1)[0]
            hook = hooks.get(alias)
            if hook:
                return alias
        else:
            for alias in hooks:
                hook = hooks[alias]
                if hook.linktable:
                    (prefix, name) = hook.linktable.split('_', 1)
                    if (name == link):
                        return alias
        return None
    hooks = components.get(tablename)
    if hooks:
        alias = get_alias(hooks, link)
        if alias:
            return alias
    supertables = cls.get_config(tablename, 'super_entity')
    if supertables:
        if (not isinstance(supertables, (list, tuple))):
            supertables = [supertables]
        for s in supertables:
            table = cls.table(s)
            if (table is None):
                continue
            hooks = components.get(table._tablename)
            if hooks:
                alias = get_alias(hooks, link)
                if alias:
                    return alias
    return None
