[1.2.2] Fix broken hasManyToMany()

Backport of 1.3.0 patch