yiisoft/yii2 — pull request #2650 by Koudy (2014-03-06 19:43:48+00:00)
Title: Fixed addind join in db/Query

I was need use joinWith in AR by the some condition, like this:
$query = User::find()->joinWith('posts');
if ($something) {
$query->joinWith('posts.comments');
}
The sql I get is :

SELECT `user`.* FROM `user`
LEFT JOIN `post` ON `user`.`id` = `post`.`user_id`
LEFT JOIN `post` ON `user`.`id` = `post`.`user_id`
LEFT JOIN `comment` ON `post`.`id` = `comment`.`post_id`

so I get mistake 'SQL Error (1066): Not unique table/alias: 'post''.
Here is my solution for this problem.