'Determine the relationship between this model and related_model, and
return a pivot iterator.
:param base_objects_by_id: dict of instances of this model indexed by
their IDs
:return: a pivot iterator, which yields a tuple (base_object,
related_object) for each relationship between a base object and a
related object.  all base_object instances come from base_objects_by_id.
Note -- this depends on Django model internals.'

def _get_pivot_iterator(self, base_objects_by_id, related_model):

    (relationship_type, field) = self.determine_relationship(related_model)
    if (relationship_type == self.MANY_TO_ONE):
        return self._many_to_one_pivot(base_objects_by_id, related_model, field)
    elif (relationship_type == self.M2M_ON_RELATED_MODEL):
        return self._many_to_many_pivot(base_objects_by_id, related_model, field.m2m_db_table(), field.m2m_reverse_name(), field.m2m_column_name())
    else:
        assert (relationship_type == self.M2M_ON_THIS_MODEL)
        return self._many_to_many_pivot(base_objects_by_id, related_model, field.m2m_db_table(), field.m2m_column_name(), field.m2m_reverse_name())
