code: def as_sql(self, qn, connection):
          
          # self.children is an array of VersionedExtraWhere-objects
          from versions.fields import VersionedExtraWhere
          for child in self.children:
              if isinstance(child, VersionedExtraWhere) and not child.params:
                  _query = qn.query
                  query_time = _query.querytime.time
                  apply_query_time = _query.querytime.active
                  alias_map = _query.alias_map
                  self._set_child_joined_alias(child, alias_map)
                  if apply_query_time:
                      # Add query parameters that have not been added till now
                      child.set_as_of(query_time)
                  else:
                      # Remove the restriction if it's not required
                      child.sqls = []
          return super(VersionedWhereNode, self).as_sql(qn, connection)
docs: This method identifies joined table aliases in order for
          VersionedExtraWhere.as_sql() to be able to add time restrictions for
          those tables based on the VersionedQuery's querytime value.
  
          :param qn: In Django 1.7 & 1.8 this is a compiler
          :param connection: A DB connection
          :return: A tuple consisting of (sql_string, result_params)