Fixes many-to-many joins in auto-generated filter forms

Solves the following exception for auto-generated filter forms with more than one many-to-many relation: SQLSTATE[42000]: Syntax error or access violation: 1066 Not unique table/alias: "tablename"

The original code generated joins from the foreign table to the target table which causes problems of duplicated alias names.