CDbCriteria questions

First off, how can I print to the page the sql generate by a CDbCriteria? I only see something when an error occurs.

Secondly, I’m trying to execute the following sql:




SELECT User.userName, sum(views) FROM Rant LEFT JOIN User ON Rant.phone = User.phone GROUP BY User.userId ORDER BY views DESC LIMIT 5;



The above sql works fine when run against the database. I have the following CDbCriteria in my controller that isn’t returning any info from the ‘user’ table:




		$criteria=new CDbCriteria;

		$criteria->select = 'sum(views) as views';

		$criteria->with = 'user';

		$criteria->order='views DESC';

		$criteria->group = 'user.userId';

		$criteria->limit=5;

		$dataProvider3=new CActiveDataProvider('Rant', array(

			'criteria'=>$criteria,

		));	

		$dataProvider->setPagination(false);



In my ‘Rant’ model I have the following:




	public function relations()

	{

		return array(

			'user' => array(self::BELONGS_TO, 'User', 'phone'),

		);

	}



My view has the following and none of the ‘user’ data is there:




<li><a href="<?=Yii::app()->baseUrl?>/userlist/<?=$data->user->userId?>"><?=$data->user->userName?></a> (<?=$data->views?> plays)</li>



The ‘phone’ field in the ‘User’ table is unique but not primary. I think this may have something to do with the issue. Any ideas?