Fix many-to-many query generation. Prepend table names when necessary.