'Return joins from this collection as list
@param tablenames: the names of the tables for which joins
shall be returned, defaults to all tables
in the collection. Dependencies will be
included automatically (if available)
@param aqueries: dict of accessible-queries {tablename: query}
to include in the joins; if there is no entry
for a particular table, then it will be looked
up from current.auth and added to the dict.
To prevent differential authorization of a
particular joined table, set {<tablename>: None}
in the dict
@param prefer: If any table or any of its dependencies would be
joined by this S3Joins collection, then skip this
table here (and enforce it to be joined by the
preferred collection), to prevent duplication of
left joins as inner joins:
join = inner_joins.as_list(prefer=left_joins)
left = left_joins.as_list()
@return: a list of joins, ordered by their interdependency, which
can be used as join/left parameter of Set.select()'

def as_list(self, tablenames=None, aqueries=None, prefer=None):

    accessible_query = current.auth.s3_accessible_query
    if (tablenames is None):
        tablenames = self.tables
    else:
        tablenames = set(tablenames)
    skip = set()
    if prefer:
        preferred_joins = prefer.as_list(tablenames=tablenames)
        for join in preferred_joins:
            try:
                tname = join.first._tablename
            except AttributeError:
                tname = str(join.first)
            skip.add(tname)
    tablenames -= skip
    joins = self.joins
    required_tables = set()
    get_tables = current.db._adapter.tables
    for tablename in tablenames:
        if ((tablename not in joins) or (tablename == self.tablename) or (tablename in skip)):
            continue
        join_list = joins[tablename]
        preferred = False
        dependencies = set()
        for join in join_list:
            join_tables = set(get_tables(join.second))
            if join_tables:
                if any(((tname in skip) for tname in join_tables)):
                    preferred = True
                dependencies |= join_tables
        if preferred:
            skip.add(tablename)
            skip |= dependencies
            prefer.extend({tablename: join_list})
        else:
            required_tables.add(tablename)
            required_tables |= dependencies
    joins_dict = {}
    for tablename in required_tables:
        if ((tablename not in joins) or (tablename == self.tablename)):
            continue
        for join in joins[tablename]:
            j = join
            table = j.first
            tname = table._tablename
            if ((aqueries is not None) and (tname in tablenames)):
                if (tname not in aqueries):
                    aquery = accessible_query('read', table)
                    aqueries[tname] = aquery
                else:
                    aquery = aqueries[tname]
                if (aquery is not None):
                    j = join.first.on((join.second & aquery))
            joins_dict[tname] = j
    try:
        return self.sort(joins_dict.values())
    except RuntimeError:
        return joins_dict.values()
