

def generate_joins(self, joins, model_class, alias_map):
    clauses = []
    seen = set()
    q = [model_class]
    while q:
        curr = q.pop()
        if ((curr not in joins) or (curr in seen)):
            continue
        seen.add(curr)
        for join in joins[curr]:
            src = curr
            dest = join.dest
            if isinstance(join.on, (Expression, Func, Clause, Entity)):
                constraint = join.on.clone().alias()
            else:
                metadata = join.metadata
                if metadata.is_backref:
                    fk_model = join.dest
                    pk_model = join.src
                else:
                    fk_model = join.src
                    pk_model = join.dest
                fk = metadata.foreign_key
                if fk:
                    lhs = getattr(fk_model, fk.name)
                    rhs = getattr(pk_model, fk.to_field.name)
                    if metadata.is_backref:
                        (lhs, rhs) = (rhs, lhs)
                    constraint = (lhs == rhs)
                else:
                    raise ValueError('Missing required join predicate.')
            if isinstance(dest, Node):
                dest_n = dest
            else:
                q.append(dest)
                dest_n = dest.as_entity().alias(dest_n[dest])
            join_type = join.get_join_type()
            if (join_type in self.join_map):
                join_sql = SQL(self.join_map[join_type])
            else:
                join_sql = SQL(join_type)
            clauses.append(Clause(join_sql, dest_n, SQL('ON'), constraint))
    return clauses

dataset/ETHPy150Open coleifer/peewee/peewee.py QueryCompiler.generate_joins/VarMisuse@288/346 `alias_map`->`dest_n`