AR query: duplicated fields

check this:

SELECT `media_body`.`id` AS t0_c0, `media_body`.`id` AS t0_c0, mediaSize.`basePath` AS t1_c4, mediaSize.`id` AS t1_c0, media.`extension` AS t2_c3, media.`id` AS t2_c0 FROM `media_body` LEFT OUTER JOIN `media_size` mediaSize ON `media_body`.`mediaSizeId`=mediaSize.`id` LEFT OUTER JOIN `media` media ON `media_body`.`mediaId`=media.`id` WHERE `media_body`.`id`=10 

we need to fix CJoinQuery::createCommand:


		for($i=0; $i<count($this->selects); ++$i)


			if(strpos($this->selects[$i], ',')!==false){

				array_splice($this->selects, $i, 1, explode(', ', $this->selects[$i]));



		$sql='SELECT ' . implode(', ',array_unique($this->selects));



		$sql='SELECT ' . implode(', ', $this->selects);

Thanks, but why there are duplicated fields?

in query:

`media_body`.`id` AS t0_c0,

`media_body`.`id` AS t0_c0,


  • if I need to select only one field (id etc.):
 with(array('someModel' => array('select' => 'id')))

in this case fields and aliases will be duplicated

Thanks. It's actually a bug caused by the code at somewhere else. I just fixed it.