public Expression twistedForBaseAndContext(
      Expression newBase, Expression context, Expression oldBase) {
    if (oldBase == null || this.typeExpressionBase == oldBase) {
      Expression twistedBase =
          this.typeExpressionBase.twistedForBaseAndContext(newBase, context, oldBase);
      TreatAsExpression result = (TreatAsExpression) twistedBase.treat(this.castClass);
      if (shouldUseOuterJoin) {
        result.doUseOuterJoin();
      }
      if (shouldQueryToManyRelationship) {
        result.doQueryToManyRelationship();
      }
      return result;
    }

    return this;
  }