Fix many-to-many association query generation.
Add unit tests for many-to-many association query generation.