Fix for many-to-many relationships

Closes #37