Duplicated Queries While Using Joinwith

I am trying to get results similar to Yii1 while using ‘together’ in the relations.

Here is an example:




$user = User::find()->joinWith(['role'])->one();

echo $user->role->name;



On mysql log I see:




140806 12:53:29	   59 Connect	root@localhost on testDB

		   59 Query	SET NAMES 'utf8'

		   59 Query	SELECT `user`.* FROM `user` LEFT JOIN `role` ON `user`.`role_id` = `role`.`id`

		   59 Query	SHOW FULL COLUMNS FROM `user`

		   59 Query	SHOW CREATE TABLE `user`

		   59 Query	SELECT * FROM `role` WHERE `id`='2'

		   59 Query	SHOW FULL COLUMNS FROM `role`

		   59 Query	SHOW CREATE TABLE `role`

		   59 Quit



I think joinwith() fails to populate the relation after using JOIN?

For me everything seems OK, or maybe you need some id for the user.

That is the only workaround just in case anybody needed it. For me I can not count on Yii2 for a big project with such design :(




$user = User::find()->leftJoin('role', 'role.id=user.role_id')->select(['user.*','role_name' => 'role.name'])->one();

echo $user->role_name;