':param m2m_field: a Django field representing the M2M relationship.
It uses a pivot table with the following structure:
this model table <---> M2M pivot table <---> joined model table
:param join_to_query: the query over the related model that we\'re
joining to.
:param alias: alias of joined table'

def _info_for_many_to_many_join(self, m2m_field, join_to_query, alias, m2m_is_on_this_model):

    if m2m_is_on_this_model:
        lhs_id_field = self.model._meta.pk
        m2m_lhs_column = m2m_field.m2m_column_name()
        m2m_rhs_column = m2m_field.m2m_reverse_name()
        rhs_id_field = m2m_field.rel.get_related_field()
    else:
        lhs_id_field = m2m_field.rel.get_related_field()
        m2m_lhs_column = m2m_field.m2m_reverse_name()
        m2m_rhs_column = m2m_field.m2m_column_name()
        rhs_id_field = join_to_query.model._meta.pk
    info = {}
    info['rhs_table'] = m2m_field.m2m_db_table()
    info['rhs_column'] = m2m_lhs_column
    info['lhs_column'] = lhs_id_field.column
    rhs_ids = join_to_query.values_list(rhs_id_field.attname, flat=True)
    assert (len(rhs_ids) == 1), 'Many-to-many    custom    field    joins    can    only    match    a    single    related    object.'
    rhs_id = rhs_ids[0]
    info['where_clause'] = ('%s.%s    =    %s' % (_quote_name(alias), _quote_name(m2m_rhs_column), rhs_id))
    info['values'] = ()
    return info
