Select only some foreign columns

Hi @ all !

I did an "eager loading" SQL request that retrieve all foreign columns using a given "postedBy" foreign key :


SELECT `t`.`id` AS `t0_c0`, `t`.`sectionId` AS `t0_c1`,

`t`.`postedBy` AS `t0_c2`, `t`.`created` AS `t0_c3`, `t`.`replyCount` AS

`t0_c4`, `t`.`viewCount` AS `t0_c5`, `t`.`closed` AS `t0_c6`, `t`.`sticky`

AS `t0_c7`, `t`.`hasPoll` AS `t0_c8`, `t`.`isActive` AS `t0_c9`,

`t`.`accessLevel` AS `t0_c10`, `post`.`id` AS `t1_c0`, `post`.`topicId` AS

`t1_c1`, `post`.`sectionId` AS `t1_c2`, `post`.`title` AS `t1_c3`,

`post`.`shortContent` AS `t1_c4`, `post`.`content` AS `t1_c5`,

`post`.`postTime` AS `t1_c6`, `post`.`postedBy` AS `t1_c7`, `user`.`id` AS

`t2_c0`, `user`.`username` AS `t2_c1`, `user`.`password` AS `t2_c2`,

`user`.`salt` AS `t2_c3`, `user`.`email` AS `t2_c4`, `user`.`screenName` AS

`t2_c5`, `user`.`language` AS `t2_c6`, `user`.`interface` AS `t2_c7`,

`user`.`accessType` AS `t2_c8`, `user`.`accessLevel` AS `t2_c9`,

`user`.`isActive` AS `t2_c10`, `user`.`createTime` AS `t2_c11` FROM

`w3_forum_topics` `t`  LEFT OUTER JOIN `w3_forum_posts` `post` ON

(`post`.`topicId`=`t`.`id`) LEFT OUTER JOIN `w3_user` `user` ON

(`t`.`postedBy`=`user`.`id`) WHERE (`t`.`sectionId`=1)

This works well but I’d like to know if it is possible to retrieve only the user.username foreign column (in order to make a shorter query and of course to do less memory usage.

Hi!

There have already been some discussion on this topic (but I cannot find them… sorry) and the main point was that the memory usage for the other columns is not influent.

I mean less CActiverecord model properties (resut of model()->findAll) should result into lighter instances so less memory usage.

Is Yii able to remove the following :


`user`.`password` AS `t2_c2`,

`user`.`salt` AS `t2_c3`,

`user`.`email` AS `t2_c4`,

`user`.`screenName` AS `t2_c5`,

`user`.`language` AS `t2_c6`,

`user`.`interface` AS `t2_c7`,

`user`.`accessType` AS `t2_c8`,

`user`.`accessLevel` AS `t2_c9`,

`user`.`isActive` AS `t2_c10`,

`user`.`createTime` AS `t2_c11` 

?

See second example

http://www.yiiframework.com/doc/api/CActiveRecord#with-detail

Something like




...->with(array('user'=>array('select'=>'id, username')))->...



or perhaps




...->with('user'=>array('select'=>'id, username'))->...



/Tommy

@tri : Thanks, that works well