'If the update depends on results from other tables, we need to do some
munging of the "where" conditions to match the format required for
(portable) SQL updates. That is done here.
Further, if we are going to be running multiple updates, we pull out
the id values to update at this point so that they don\'t change as a
result of the progressive updates.'

def pre_sql_setup(self):

    self.query.select_related = False
    self.query.clear_ordering(True)
    super(SQLUpdateCompiler, self).pre_sql_setup()
    count = self.query.count_active_tables()
    if ((not self.query.related_updates) and (count == 1)):
        return
    query = self.query.clone(klass=Query)
    query.bump_prefix()
    query.extra = {}
    query.select = []
    query.add_fields([query.get_meta().pk.name])
    count = query.count_active_tables()
    if ((not self.query.related_updates) and (count == 1)):
        return
    must_pre_select = ((count > 1) and (not self.connection.features.update_can_self_select))
    self.query.where = self.query.where_class()
    if (self.query.related_updates or must_pre_select):
        idents = []
        for rows in query.get_compiler(self.using).execute_sql(MULTI):
            idents.extend([r[0] for r in rows])
        self.query.add_filter(('pk__in', idents))
        self.query.related_ids = idents
    else:
        self.query.add_filter(('pk__in', query))
    for alias in self.query.tables[1:]:
        self.query.alias_refcount[alias] = 0
