'Get a non-null column on the table joined for the given query.
This analyzes the join that would be produced if join_to_query were
passed to join_custom_field.'

def key_on_joined_table(self, join_to_query):

    (relationship_type, field) = self.determine_relationship(join_to_query.model)
    if (relationship_type == self.MANY_TO_ONE):
        return join_to_query.model._meta.pk.column
    return field.m2m_column_name()
