':param pivot_table: see _query_pivot_table
:param pivot_from_field: see _query_pivot_table
:param pivot_to_field: see _query_pivot_table
:return: a pivot iterator - see _get_pivot_iterator()'

def _many_to_many_pivot(self, base_objects_by_id, related_model, pivot_table, pivot_from_field, pivot_to_field):

    id_pivot = self._query_pivot_table(base_objects_by_id, pivot_table, pivot_from_field, pivot_to_field)
    all_related_ids = list(set((related_id for (base_id, related_id) in id_pivot)))
    related_objects_by_id = related_model.objects.in_bulk(all_related_ids)
    for (base_id, related_id) in id_pivot:
        (yield (base_objects_by_id[base_id], related_objects_by_id[related_id]))
