Try to invalidate m2m in more robust way

Hi!

I faced with bug when m2m is used with multi-table inheritance model. But I think that similar bug can occur, when the handmade `through`-model is used in m2m relation (i.e. through-model field names are not correspond to the names of related models)

The changes contain fix for such cases. Tests are included. Please review these.

Thanks!