'Adapt incoming clauses to transformations which
have been applied within this query.'

def _adapt_clause(self, clause, as_filter, orm_only):

    adapters = []
    orm_only = getattr(self, '_orm_only_adapt', orm_only)
    if (as_filter and self._filter_aliases):
        for fa in self._filter_aliases._visitor_iterator:
            adapters.append((orm_only, fa.replace))
    if self._from_obj_alias:
        adapters.append((getattr(self, '_orm_only_from_obj_alias', orm_only), self._from_obj_alias.replace))
    if self._polymorphic_adapters:
        adapters.append((orm_only, self._adapt_polymorphic_element))
    if (not adapters):
        return clause
    def replace(elem):
        for (_orm_only, adapter) in adapters:
            if ((not _orm_only) or ('_orm_adapt' in elem._annotations) or ('parententity' in elem._annotations)):
                e = adapter(elem)
                if (e is not None):
                    return e
    return visitors.replacement_traverse(clause, {}, replace)
