'Change join type from LOUTER to INNER for all joins in aliases.
Similarly to promote_joins(), this method must ensure no join chains
containing first an outer, then an inner join are generated. If we
are demoting b->c join in chain a LOUTER b LOUTER c then we must
demote a->b automatically, or otherwise the demotion of b->c doesn\'t
actually change anything in the query results. .'

def demote_joins(self, aliases):

    aliases = list(aliases)
    while aliases:
        alias = aliases.pop(0)
        if (self.alias_map[alias].join_type == LOUTER):
            self.alias_map[alias] = self.alias_map[alias].demote()
            parent_alias = self.alias_map[alias].parent_alias
            if (self.alias_map[parent_alias].join_type == INNER):
                aliases.append(parent_alias)
