removed duplicated joins when using joinWith and via relations

fixes #2650