Fix generation of forward and reverse m2m queries.