removed duplicated joins when using joinWith and via relations

fixes #2650
Merge pull request #2981 from yiisoft/fix-duplicated-joins

removed duplicated joins when using joinWith and via relations