':param id_list list of IDs of self.model objects to include
:param pivot_table the name of the pivot table
:param pivot_from_field a field name on pivot_table referencing
self.model
:param pivot_to_field a field name on pivot_table referencing the
related model.
:return: pivot list of IDs (base_id, related_id)'

def _query_pivot_table(self, base_objects_by_id, pivot_table, pivot_from_field, pivot_to_field):

    query = ('\n                                SELECT    %(from_field)s,    %(to_field)s\n                                FROM    %(table)s\n                                WHERE    %(from_field)s    IN    (%(id_list)s)\n                                ' % dict(from_field=pivot_from_field, to_field=pivot_to_field, table=pivot_table, id_list=','.join((str(id_) for id_ in base_objects_by_id.iterkeys()))))
    cursor = readonly_connection.connection().cursor()
    cursor.execute(query)
    return cursor.fetchall()
